Why does the datagrid's textbox contain the original value when in edit mode

C

CW

I am taking the Commerce Starter Kit sample from asp.net and trying to add a
page that allows user to edit product categories.

I am doing so via the use of a datagrid. html portion related to the data
grid is as per follows:

<asp:datagrid id=dgProductCategories runat="server"
AutoGenerateColumns="False" DataSource="<%# DataSet11 %>" Width="275px"
BorderColor="#999999" BorderStyle="None" BackColor="White" CellPadding="3"
GridLines="Vertical" BorderWidth="1px" DataKeyField="CategoryID"
DataMember="CMRC_Categories">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black"
BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="CategoryID"
SortExpression="CategoryID" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="CategoryName"
SortExpression="CategoryName" HeaderText="Category Name"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

The code behind that handles the Update command is as per follows:

Private Sub dgProductCategories_UpdateCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgProductCategories.UpdateCommand
Dim dr As DataSet1.CMRC_CategoriesRow
dr =
Me.DataSet11.CMRC_Categories.FindByCategoryID(CInt(Me.dgProductCategories.It
ems(e.Item.ItemIndex).Cells(0).Text))
Dim tbProductCategory As System.Web.UI.WebControls.TextBox =
CType(e.Item.Cells(1).Controls(0), System.Web.UI.WebControls.TextBox)
dr.Item(1) = tbProductCategory.Text
Me.SqlDataAdapter1.Update(Me.DataSet11)
Me.dgProductCategories.EditItemIndex = -1
Me.dgProductCategories.DataBind()
End Sub

e.Item.Cells(1).Controls(0) supposed to the be the textbox when datagrid is
in edit mode. However, in debug mode, I could tell that the value in the
text box is the original value, rather than the edited value. Of course this
means that the edit operation would have no effect.

I also tried using
Me.dgProductCategories.Items(e.Item.ItemIndex).Cells(1).Controls(0) instead
of e.Item.Cells(1).Controls(0) in the code. However, it made no difference.

Any idea what's happening there?

Thanks in advance

CW
 
C

CW

I didn't have
If !Page.IsPostBack
//bind data source

in the code

CW said:
I am taking the Commerce Starter Kit sample from asp.net and trying to add a
page that allows user to edit product categories.

I am doing so via the use of a datagrid. html portion related to the data
grid is as per follows:

<asp:datagrid id=dgProductCategories runat="server"
AutoGenerateColumns="False" DataSource="<%# DataSet11 %>" Width="275px"
BorderColor="#999999" BorderStyle="None" BackColor="White" CellPadding="3"
GridLines="Vertical" BorderWidth="1px" DataKeyField="CategoryID"
DataMember="CMRC_Categories">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top