如何将值从文本框保存到网格 [英] How to save values from textbox to grid

查看:92
本文介绍了如何将值从文本框保存到网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我模块的前端是,

名称--------------
年龄--------------

[提交] [保存]


输入姓名和年龄后,如果我给提交"按钮,姓名和年龄将被保存在网格中,而如果我给了提交",则值和年龄将被保存在Excel中.
现在,我想向网格添加多个值.提交后,文本字段中的值应保存在网格中,文本字段应为空,以便我可以一次又一次添加多个值并将其保存在网格中.

谁能帮我解决这个问题...

多谢. :)

Anusha

Hi,

My module''s front end is,

Name --------------
Age --------------

[submit] [save]


After entering name and age, if i give submit button, the name and age will be saved in a grid and after tat if i give submit, the value will be saved in an Excel..

Now, I want to add multiple values to the grid.. eg. after giving submit, the value in the text field should be saved in the grid and the text field should become empty so that i can add multiple vales again and again and saved in grid..

Can anyone help me out on how to do this...

thanks a lot. :)

Anusha

推荐答案

要将值添加到网格,请尝试以下操作:
To add values to grid, try this:
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
           TextBox t1 = (TextBox)GridView1.Rows[i].FindControl("tt1");
           TextBox t2 = (TextBox)GridView1.Rows[i].FindControl("tt2");
           if(t1 != null)
           t1.Text = TextBox1.Text;
           if (t2 != null)
           t2.Text = TextBox1.Text;
       }
   }



要在excel中导出,请尝试以下操作:



To export it in excel, try this:

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=GridView1.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter StringWriter = new System.IO.StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
GridView1.RenderControl(HtmlTextWriter);
Response.Write(StringWriter.ToString());
Response.End();


这篇关于如何将值从文本框保存到网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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