Datagrid won't let me edit

greenmeanie

New Member
I've been going through the tutorials at the "Got Dot Net" site trying to learn ASP.NET. I've been reading about the DataGrid control and can see that it can be a really cool way to handle data display.<BR><BR>I can't get it to let me edit the data displayed though. I think I'm doing everything according to the tutorial so I don't know what could be wrong. The data is displayed, but when I click on the "Edit" button, nothing changes. Plus, you'll notice in my code below that I am also trying to use a template column to have a checkbox displayed for a boolean value ("Original"). The column gets displayed but the checkbox doesn't.<BR><BR>Could someone please help me with this? I can't find the answer anywhere else so far.<BR><BR>Thank you in advance. Here's the code I'm using right now:<BR><BR><BR><%@ Page Language="vb" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.SQL" %><BR><BR><script language="vb" runat="server"><BR> sub BindGrid()<BR> dim oDS as DataSet<BR> dim oConn as SQLConnection<BR> dim oCmd as SQLDataSetCommand<BR> dim sConn as string<BR> dim sQuery as string<BR> dim htAppSettings as HashTable = Context.GetConfig("appsettings")<BR><BR> sConn = htAppSettings("MySQLServerKey")<BR> sQuery = "select top 10 * from Parcel"<BR><BR> oConn = new SQLConnection(sConn)<BR> oCmd = new SQLDataSetCommand(sQuery, oConn)<BR> oDS = new DataSet()<BR> oCmd.FillDataSet(oDS, "Parcel")<BR><BR> dgGrid.DataSource = oDS.Tables("Parcel").DefaultView<BR> dgGrid.DataBind()<BR> end sub<BR> <BR> sub Page_Load(src as Object, e as EventArgs)<BR> BindGrid()<BR> end sub<BR> <BR> sub dgGrid_Edit(sender As Object, e As DataGridCommandEventArgs)<BR> dgGrid.EditItemIndex = CInt(e.Item.ItemIndex)<BR> BindGrid()<BR> end sub<BR> <BR> sub dgGrid_Cancel(sender As Object, e As DataGridCommandEventArgs)<BR> dgGrid.EditItemIndex = -1<BR> BindGrid()<BR> end sub<BR> <BR> sub dgGrid_Update(sender As Object, e As DataGridCommandEventArgs)<BR> 'Update functionality not yet implemented<BR> BindGrid()<BR> end sub<BR></script><BR><BR><html><BR><head><BR> <title>DataGrid Test</title><BR></head><BR><BR><body><BR><BR><table border="0" cellspacing="0" cellpadding="0" align="center"><BR><tr><BR> <td><BR> <font face="arial" size="2"><BR> <BR> <asp:datagrid id="dgGrid" runat="server"<BR> width="100%"<BR> backcolor="#ffffff"<BR> alternatingitemstyle-backcolor="#eeeeee"<BR> bordercolor="#000000"<BR> showfooter="false"<BR> cellpadding="3"<BR> cellspacing="0"<BR> font-name="verdana"<BR> font-size="8pt"<BR> headerstyle-backcolor="#00aacc"<BR> headerstyle-font-size="10pt"<BR> headerstyle-font-style="bold"<BR> maintainstate="true"<BR> autogeneratecolumns="false"<BR> oneditcommand="dgGrid_Edit"<BR> oncancelcommand="dgGrid_Cancel"<BR> onupdatecommand="dgGrid_Update"<BR> ><BR> <property name="Columns"><BR> <asp:boundcolumn headertext="ParcelID" datafield="ParcelID" readonly="true" /><BR> <BR> <asp:hyperlinkcolumn<BR> headertext="Link"<BR> datatextfield="Parcel"<BR> datanavigateurlfield="ParcelID"<BR> datanavigateurlformatstring="fakepage.asp?id={0}"<BR> target="new"<BR> /><BR> <BR> <asp:boundcolumn headertext="Active" datafield="Active" readonly="false" /><BR> <BR> <asp:templatecolumn headertext="Original"><BR> <template name="EditItemTemplate"><BR> <asp:checkbox<BR> runat="server"<BR> id="chkOriginal"<BR> checked='<%# DataBinder.Eval(Container.DataItem, "Original")%>'<BR> /><BR> </template><BR> </asp:templatecolumn><BR> <BR> <asp:editcommandcolumn<BR> edittext=" Edit "<BR> canceltext=" Cancel "<BR> updatetext=" Update "<BR> itemstyle-wrap="false"<BR> headertext="Action"<BR> headerstyle-wrap="false"<BR> /><BR> </property><BR> </asp:datagrid><BR> <BR> </font><BR> </td><BR></tr><BR></table><BR><BR></body><BR></html>You've got to put the datagrid control in a serverside form:<BR><BR><form runat="server"><BR><BR><asp:datagrid ... /><BR><BR></form><BR><BR>Happy Programming!Thank you very much. It works fine now. How silly of me!<BR><BR>Thank you again!
 
Back
Top