Friday, September 10, 2010

ve: page with gridview from db, on the way to updating records with geocode

Posted by david on 1. February 2009 23:40

so add LinqDataSource

been so long since I’ve fooled with the db that I’ve forgotten whether things were straight in there.

open up SS08. Look.

I’ve got a list of POI .. but not a corresponding list of shapes that will represent the POIs.

POI: Places of Interest

this is the list of spots that is independent of the map … this list could be a source for a similar implementation on GMAPS or some other system. 

DBShapes: is the table of MapShapes one for each POI.  The MapShape is coupled with Virtual Earth.  It’s got the same fields that a MapShape object has. 

there is another:

DBPoints: is the table of MapPoints … there is one or more Point for every shape. If you’ve got an area to define, it will be defined by a set of points … say the four corners of a city block.  My list of city parks has acreage, I’ve got that data .. but I don’t have the points that encompass that area.  All I’ve got right now is an address. Which is a single point.  However, that could be easily updated later … simply add more points to the shape.

My original design didn’t have lat long fields in the POI table.  That is a Point level property.  I realize now that my POI table is not so transferable without that lat long info, and actually, without a field that will hold an array of points … which is available in some geo feeds.

So add the two columns, then go into my LinqDataSource designer … figure out how to refresh the POI table.  Ended up removing it then dragging it back from the Server Explorer.

Go back to my page, configure my Data Source there. Why don’t I have a zip in the table? Shite. Later.

Add a ScriptManager.

Add an Update Panel.

Add a gridview to the Update Panel.

Save & open.

Works … but I am reminded, now, of the hassle I went through to limit the size of the gridview.

So, how do I take the address of one of those records & pass it to my geocode code & then update the record with the returned Lat Long?

Added paging & select to the gridview.  All ugly – but I’ll get the functionality first .. then go back & fix things up.

I wanted to get a few fields to represent selected row on to the page … so I’m back into the CSS styling of a gridview.  My aim was to contain the gridview into a left column & stick the child fields in a right column. 

first attempt: add a left & right div inside of the updatepanel.

result: gridview broke right out. got down right ugly.

second attempt: size the left & right divs. didn’t help much, but did push down the footer content … but that was because I pushed it down with the div, not by containing the gridview.

searching for answers:

Matt Dotson’s Real World GridView

DotNetBips

Grid view of fixed size at run time forum

ooh note that there is a rounded corner extender for the gridview

oh – maybe I need a wrapper for the two columns.

#leftrightwrapper
{
    border-style: dotted;
    border-color: #FF0000;
    width: 100%;
    height: 100%;
}
#left
{
    border: thin groove #008000;
    width: 60%;
    float: left;
    margin: 10px;
    padding: 5px;  
}
#right
{
border: thin groove #008000;
width: 35%;
height: 90%;
float: left;
margin: 10px;
padding: 5px;
}
#POIgrid
{
float:left;
}
#UpdatePanel1
{
    height: 500px;
    padding: 15px;
    margin: 15px;
    font-family: Candara;
    line-height: 25px;
    background-color: #CCFFCC;
    border-style: groove;
    border-width: thin;
}

that’s the ticket:

boxedgrid

that will do for now.

Add the fields .. and a little more CSS to make them behave:

#UpdatePanel1
{
    height: 500px;
    padding: 15px;
    margin: 15px;
    font-family: Candara;
    line-height: 25px;
    background-color: #CCFFCC;
    border-style: groove;
    border-width: thin;
}
 
#leftrightwrapper
{
    border-style: dotted;
    border-color: #FF0000;
    width: 100%;
    height: 100%;
}
 
 
#left
{
    border: thin groove #008000;
    width: 60%;
    float: left;
    margin: 10px;
    padding: 5px;
    
}
#POIgrid
{
float:left;
}
#right
{
border: thin groove #008000;
width: 35%;
height: 90%;
float: left;
margin: 10px;
padding: 5px;
text-align: left;
}
.SelectedRecordRow
{
text-align: left;
margin: 5px;
}

 

addfields

remember this: Displaying Master/Detail Data from an Object

damn i messed up … should have used another data control instead of the individual fields.  & I was really proud of the css there … i comment out all those rows.

Add the DetailsView control into the right div

Set the datasource to same as the gridview

Configure datasource, WHERE POI_ID’s ==

aw – It’s like I’ve been snowboarding all day & just had my first fall:

Server Error in '/' Application  Data keys must be specified on GridView 'POIgrid' before the selected data keys can be retrieved.  Use the DataKeyNames property to specify data keys.

Configure datasource for POIgrid, add in POI_ID

POIgrid properties, set datakeyname to POI_ID ( how do i make that column inveeesable now? )

Oh horror!

Server Error in '/' Application. Operator '==' incompatible with operand types 'Int32' and 'Object'

this is because, in the datasource config for the details table, I used a Where == POI_Grid.SelectedValue .  That’s the only thing that makes any sense to me … maybe I don’t have the POI_grid selecting the right value….

searching for answers I find a cool looking implementation of this:

Master-Detail with the GridView, DetailsView and ModalPopup Controls

shite shite shite

I am not trying to do a master detail here … displaying the record of one table that is linked to another table. I am displaying the same table in a single record form.

btw here is the code to populate other controls with data from within a selected row of a gridview

& I forgot that I ran into this same problem the last time I was doing this gridview stuff …

Mr.Raj Kaimal saves my ass again with his posting of common LinqDataSource exceptions.  He explains:

This is part of the classic Master/Details scenario where the LinqDataSource fetches the Order Details based on the OrderID selected in the GridView1.

“When the page loads the first time, the OrderID ControlParameter is equal to GridView1.SelectedValue.  GridView1.SelectedValue is null since no record has been selected in the GridView1 yet.  Unfortunately,  the LinqDataSource still attempts to fetch the data. The Linq expression parser treats the null  parameter as type Object and the comparison fails because it was expecting type Int32.” ( ! )

I created a separate datasource for the detailsView, LinqDataSource2. I used the code Kaimal provided:

protected void LinqDataSource2_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{ 
    foreach 
        (KeyValuePair<string, object> kvp in e.WhereParameters) 
        { 
            if (kvp.Value == null) 
        { e.Cancel = true; return; } 
    } 
}

actually the code didn’t work for me this time … it did last go round. So I’ve got detailsView with a parameter based on selectedvalue in POIgrid. If I let POIgrid default selection stay –1 ( the default ) this page still breaks despite Kaimal’s code. I can’t figure out where I went wrong – but I set the default selection of POIgrid to 0 & it works.  Page comes up with the details view displaying the record for index 0.

I still don’t have the update with geocode process worked out.  Here's the page 2009_02_02

Comments

Add comment


 

biuquote
Loading