Here's the code. At least the stuff I thought was relevant.
<asp:datagrid id="details" runat="server"
visible="False"
datakeyfield="entity_id"
autogeneratecolumns="False"
headerstyle-font-bold="True"
font-size="10pt"
font-name="Verdana"
oneditcommand="onEdit"
oncancelcommand="onCancel"
onupdatecommand="onUpdate"<columns>
<asp:boundcolumn headertext="ID" datafield="entity_id"
readonly="True" />
<asp:templatecolumn headertext="Name">
<itemtemplate>
<asp:label runat="server" id="lblName"
text='<%# DataBinder.Eval( Container.DataItem, "entity_name"
) %>' />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtName" runat="server" font-name="Verdana"
text='<%# DataBinder.Eval( Container.DataItem, "entity_name"
) %>' />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="Number">
<itemtemplate>
<asp:label id="lblNumber" runat="server"
text='<%# DataBinder.Eval( Container.DataItem,
"street_number" ) %>' />
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlNumber" runat="server"
datasource='<%# getStreetNumbers() %>'
datatextfield="street_number"
datavaluefield="id"
onprerender="setItemIndex" />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Street">
<itemtemplate>
<asp:label runat="server" text='<%#
DataBinder.Eval( Container.DataItem, "street_name" ) + " "
+
DataBinder.Eval( Container.DataItem, "street_type" ) %>' />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Phone 1">
<itemtemplate>
<asp:label id="lblPhone1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone1" )
%>' />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtPhone1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone1" )
%>'
width="80" />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Phone 2">
<itemtemplate>
<asp:label id="lblPhone2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone2" )
%>' />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtPhone2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "phone2" )
%>'
width="80" />
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Type">
<itemtemplate>
<asp:label id="lblType" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "type" ) %>'
/>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlType" runat="server"
datasource='<%# getTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Sub Type 1">
<itemtemplate>
<asp:label id="lblSubType1" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "subtype1" )
%>' />
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlSubType1" runat="server"
datasource='<%# getSubTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn runat="server" headertext="Sub Type 2">
<itemtemplate>
<asp:label id="lblSubType2" runat="server"
text='<%# DataBinder.Eval( Container.DataItem, "subtype2" )
%>' />
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlSubType2" runat="server"
datasource='<%# getSubTypes() %>'
datatextfield="type"
datavaluefield="id"
onprerender="setItemIndex"
/>
</edititemtemplate>
</asp:templatecolumn>
<asp:editcommandcolumn
edittext="Edit"
canceltext="Cancel"
updatetext="Save" />
<asp:buttoncolumn
buttontype="LinkButton"
commandname="Delete"
text="Delete" />
</columns>
</asp:datagrid>
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if( !IsPostBack )
{
streetId = "1";
bindGrid();
}
else {
// Get the current selection from the list box
streetId = streetList.selectedItemValue == "" ? "1" :
streetList.selectedItemValue;
// Show results
details.Visible = true;
street_image.Visible = true;
}
}
private void bindGrid()
{
string connectString =
System.Configuration.ConfigurationSettings.AppSettings[
"connectString" ];
// Create connection and set connection string
OleDbConnection cnn = new OleDbConnection( connectString );
string sql = "SELECT entity.id AS entity_id, entity.name AS
entity_name, " +
"block_address.id AS block_address_id,
block_address.street_number, street.name AS street_name, " +
"street.type AS street_type, entity.phone1, entity.phone2, "
+
"(SELECT type FROM entity_type WHERE id = entity.type ) AS
type, " +
"(SELECT type FROM entity_sub_type WHERE id =
entity.sub_type1 ) AS subtype1, " +
"(SELECT type FROM entity_sub_type WHERE id =
entity.sub_type2 ) AS subtype2, " +
"block_address.block_id " +
"FROM entity INNER JOIN " +
"( block_address INNER JOIN street " +
"ON block_address.street_id = street.id) " +
"ON entity.block_address = block_address.id " +
"WHERE street.id = " + streetId;
OleDbCommand cmd = new OleDbCommand( sql, cnn );
cmd.CommandType = CommandType.Text;
cnn.Open();
details.DataSource = cmd.ExecuteReader();
details.DataBind();
cnn.Close();
}
public void onUpdate( Object source, DataGridCommandEventArgs e )
{
string name = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string addressId = ((DropDownList)(e.Item.FindControl( "ddlNumber"
))).SelectedItem.Value;
string phone1 = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
string phone2 = ((TextBox)e.Item.Cells[5].Controls[1]).Text;
string type = ((DropDownList)(e.Item.FindControl( "ddlType"
))).SelectedItem.Value;
string subType1 = ((DropDownList)(e.Item.FindControl( "ddlSubType1"
))).SelectedItem.Value;
string subType2 = ((DropDownList)(e.Item.FindControl( "ddlSubType2"
))).SelectedItem.Value;
int entityId = e.Item.ItemIndex;
string sql = "UPDATE entity SET " +
"name = '" + name + "', " +
"block_address = " + addressId + ", " +
"phone1 = '" + phone1 + "', " +
"phone2 = '" + phone2 + "', " +
"type = " + type + ", " +
"sub_type1 = " + subType1 + ", " +
"sub_type2 = " + subType2 + " " +
"WHERE id = " + details.DataKeys[entityId];
string connectString =
System.Configuration.ConfigurationSettings.AppSettings[
"connectString" ];
// Create connection and set connection string
OleDbConnection cnn = new OleDbConnection( connectString );
OleDbCommand cmd = new OleDbCommand( sql, cnn );
cnn.Open();
cmd.ExecuteNonQuery();
details.EditItemIndex = -1;
bindGrid();
}
Thanks,
Kevin