Click here to Skip to main content
14,428,673 members
Rate this:
Please Sign up or sign in to vote.
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 :
/////////////// 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 6: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?
Rate this:
Please Sign up or sign in to vote.

Solution 1

If you are using TextBox inside TemplateField, then below should work.
donamount.Amount = ((TextBox)GridView1.Rows[i].Cells[2].FindControl("TextBox1")).Text;
Rate this:
Please Sign up or sign in to vote.

Solution 3

use following gridview selected index changed event

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


put button command name as select

<asp:TemplateField HeaderText="MyColumn">
                   <ItemTemplate>
                       <asp:Button ID="Button2" runat="server"                          Text="Save" CommandName="Select"/>
                   </ItemTemplate>
               </asp:TemplateField>
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Try Like This
Textbox txt=((TextBox)GridView1.Rows[i].Cells[2].FindControl("TextBox1")).Text;
donamount.Amount=txt.Text
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100