我在我的网站使用gridview控件我有一个问题 [英] im use a gridview control in a my website i have a problem

查看:98
本文介绍了我在我的网站使用gridview控件我有一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是



i在我的网站中使用gridview控件在gridview中我使用文本框输入值后输入值用户保存按钮文本框值保存在变量中

但问题是值无法获取变量



我的代码是:

  ///   ////////////按钮点击事件
{
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);
}
}

解决方案

如果您使用 TextBox TemplateField 里面,然后在下面工作。

 donamount.Amount =((TextBox)GridView1.Rows [i] .Cells [ 2 ]。FindControl(  TextBox1))。文本; 


使用以下gridview选择的索引更改事件



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





将按钮命令名称设为选择



 <   asp:TemplateField     HeaderText   =  MyColumn >  
< ItemTemplate >
< asp:按钮 ID = Button2 runat = server < span class =code-attribute> 文字 = 保存 CommandName = 选择 / >
< / ItemTemplate >
< / asp:TemplateField >


试试这样

Textbox txt =((TextBox)GridView1.Rows [i] .Cells [2] .FindControl(TextBox1))。Text;

donamount.Amount = txt的.text

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);
    }
}

解决方案

If you are using TextBox inside TemplateField, then below should work.

donamount.Amount = ((TextBox)GridView1.Rows[i].Cells[2].FindControl("TextBox1")).Text;


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>


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


这篇关于我在我的网站使用gridview控件我有一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆