damuzu 0 Newbie Poster

screenshot for edit gridview : http://img829.imageshack.us/img829/2304/06v6.png

screenshot for update gridview : http://img801.imageshack.us/img801/3417/j4p1.png

this is my code inside tag <body> :

<form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server"
            OnRowCancelingEdit="GridView1_RowCancelingEdit"
            OnRowUpdating="GridView1_RowUpdating"
            OnRowEditing="GridView1_RowEditing"
            OnRowDeleting="GridView1_RowDeleting" CellPadding="4" ForeColor="#333333" 
            GridLines="None" AutoGenerateColumns="False" 
            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <Columns>
                <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                <asp:BoundField DataField="p_user_name_id" Visible="false" HeaderText="p_user_name_id" />
                <asp:TemplateField Visible=true HeaderText="Username">
                  <EditItemTemplate>
                    <asp:TextBox ID="textBox1" Width="100%" Height="100%" runat="server" Text='<%# Bind("username") %>'>
        </asp:TextBox>
                  </EditItemTemplate>
                  <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("username") %>' Font-Size="Medium"></asp:Label>
                  </ItemTemplate>
             </asp:TemplateField>

             <asp:TemplateField Visible=true HeaderText="Birth Place">
                 <EditItemTemplate>
                   <asp:TextBox ID="textBox2" Width="100%" Height="100%" runat="server" Text='<%# Bind("birth_place") %>'>
                   </asp:TextBox>
                 </EditItemTemplate>
                 <ItemTemplate>
                   <asp:Label ID="Label2" runat="server" Text='<%# Bind("birth_place") %>' Font-Size="Medium"></asp:Label>
                 </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="username" HeaderText="username" Visible="false"/>
            <asp:BoundField DataField="birth_place" HeaderText="birth_place" Visible="false"/>
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
</form>

and this is the function for updating event :

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    TextBox new_username = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("textBox1");
    TextBox new_birth_place = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("textBox2");
    Response.Write(new_username.Text + " " + new_birth_place.Text);
}

there I tried to print the new username text value but what I get is the default value. How I can get the new value after I click update button ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.