Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Questioni have put gridview page in aspx page i want to get value of bound field when click on edit button.
i have write below code on edit button

C#
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow gvRow = gv1.Rows[e.RowIndex];
        string Name = gvRow.Cells[1].Text;
    }

gvRow.Cells[1].Text retrun "" insted of value

XML
<asp:GridView ID="gv1" runat="server" EmptyDataText="No Record Found"
                       Width = "100%" AllowPaging="True" PageSize="2"
                       onpageindexchanging="gv1_PageIndexChanging" AutoGenerateColumns="False"
                       AllowSorting="true" onrowediting="gv1_RowEditing"
                       AutoGenerateEditButton="true" onrowupdating="gv1_RowUpdating" DataKeyNames="Name">
                       <Columns>
                           <asp:BoundField AccessibleHeaderText="Name" HeaderText = "Name"
                               ItemStyle-Wrap="true" DataField="Name" InsertVisible="true">
                               <HeaderStyle Font-Size="Large" Wrap="false" />
                               <FooterStyle ForeColor="Yellow" />
                               <ItemStyle Font-Italic="true" BackColor="ActiveBorder" Font-Size="Large" />
                           </asp:BoundField>
                           <asp:BoundField HeaderText="Amount" DataField="Amount"
                               ConvertEmptyStringToNull="false" DataFormatString="{0:C}"/>
                       </Columns>
                   </asp:GridView>
Posted
Comments
pankajupadhyay29 1-Mar-11 11:52am    
did you want access amount value for name value us Cells[0]???
jatinchandarana 1-Mar-11 11:57am    
no i don't get value of any cell...
i don't want to use template field and datakeys...
pankajupadhyay29 1-Mar-11 11:58am    
then what you try in
string Name = gvRow.Cells[1].Text;
jatinchandarana 1-Mar-11 12:02pm    
i want value of Amount field...
but i am not able to get value of any field...

1 solution

Try this, it will works.
C#
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow gvRow = gv1.Rows[e.RowIndex];
        string Name = ((TextBox) gvRow.Cells[1].Controls[0]).Text;
    }


Or
C#
protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string Name = ((TextBox) gv1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
    }
 
Share this answer
 
Comments
jatinchandarana 1-Mar-11 12:06pm    
ya,you solved my problem...
TweakBird 1-Mar-11 12:09pm    
Thank you.
jatinchandarana 1-Mar-11 12:38pm    
<asp:BoundField AccessibleHeaderText="Name" HeaderText = "Name"
ItemStyle-Wrap="true" DataField="Name" Visible="false">
then how i can get value of this bound field
TweakBird 1-Mar-11 13:16pm    
You can check through 'intelligence' of ((TextBox) gv1.Rows[e.RowIndex].Cells[1].'Here you will get lot properties'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900