Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my question is

i am using a gridview control in my website in a gridview i am use a textbox for enter a value after enter a value user pres a save button textbox value save in a variable
but problem is that value cannot get in a variable

my code is :
C#
/////////////// button click event
{
    List<donorAmount> donorinfo = new List<donorAmount>();
    donorAmount donamount = new donorAmount();
    for (int i = 0; i &lt; GridView1.Rows.Count; i++)
    {
        donamount.Amount = GridView1.Rows[i].Cells[2].Text;
        // donamount.Amount = GridView1.Rows[1].Cells[2].Text;
        donorinfo.Add(donamount);
    }
}
Posted
Updated 7-Nov-13 5:57am
v2
Comments
ZurdoDev 7-Nov-13 11:02am    
What? Please debug your code and explain clearly what is wrong.
Richard MacCutchan 7-Nov-13 11:58am    
And what happens to your donorinfo List when you return from this method?

If you are using TextBox inside TemplateField, then below should work.
C#
donamount.Amount = ((TextBox)GridView1.Rows[i].Cells[2].FindControl("TextBox1")).Text;
 
Share this answer
 
use following gridview selected index changed event

C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
      {
          string str = ((TextBox)GridView1.Rows[GridView1.SelectedIndex].FindControl("TextBox1")).Text;
      }


put button command name as select

XML
<asp:TemplateField HeaderText="MyColumn">
                   <ItemTemplate>
                       <asp:Button ID="Button2" runat="server"                          Text="Save" CommandName="Select"/>
                   </ItemTemplate>
               </asp:TemplateField>
 
Share this answer
 
Try Like This
Textbox txt=((TextBox)GridView1.Rows[i].Cells[2].FindControl("TextBox1")).Text;
donamount.Amount=txt.Text
 
Share this answer
 

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