Results 1 to 2 of 2

Thread: ASP:Datagrid Editing problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    KL Malaysia
    Posts
    64

    ASP:Datagrid Editing problem

    Here's the code for the web form:
    Code:
    ...
    <asp: DataGrid ...>
        <Columns>
            ....
            <asp:TemplateColumn HeaderText="Name">
                <ItemTemplate>
                    <%# Container.DataItem("name")
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Container.DataItem("custom") %>' 
                    CssClass="textbox2" ID="txtName" />
                 </EditItemTemplate>
              </asp:TemplateColumn>
        </Columns>
    </asp: DataGrid>
    .. and the code behind ...
    Code:
    Private Sub dgAdd_UpdateCommand(ByVal source As Object, 
    ByVal e As DataGridCommandEventArgs) Handles dgAdd.UpdateCommand
        Dim strName As String
        Dim txtNameReplica as TextBox
        txtNameReplica = e.Item.Cells(1).Control(1), TextBox
        strName = txtNameReplica.Text
        Response.Write(strName)
    End Sub
    Problem is whatever I enter into the txtName textbox in the datagrid on Editing mode and click on update (which is handled by dgAdd_UpdateCommand sub), the sub will only write the old value. For example, when the name is originally Karl Moore, and when I type in Carl More, the sub will write Karl Moore instead of Carl More. I tried disabling EnableViewState on the textbox but it still doesn't work.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    KL Malaysia
    Posts
    64
    Problem solved. I need to add a conditional statement in Page_Load sub to prevent the information to be refreshed:
    Code:
    ...
    If Not IsPostBack Then
         BindData()
    End If
    As usual, I hope this helps for some people who are stuck with the same problem...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width