插入之前如何在gridview中显示数据 [英] how to display the data in gridview before inserting

查看:53
本文介绍了插入之前如何在gridview中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些3下拉列表和两个文本框.每次我更改这些控件的值时,我想在gridview中显示这些控件的值.应将其添加到gridview.

在gridview中添加最多10条记录后,我希望将它们全部一次插入数据库中...

请给我一些建议.请


非常紧急.

i have some 3 dropdown list and two textboxes.and the value from these controls i want to dispalay in gridview , every time when i change the values of these controls.it should be added to the gridview.

and after adding max 10 records in gridview i want them all to be inserted into the database at once...

please gv me some suggestions. please


Its very urgent.

推荐答案



我尝试过一些代码供您检查一次,

这只是一个示例,以使您了解如何执行此操作.在此示例中,我仅使用了会话变量来存储输入的数据.

Hi ,

I tried some code for you check this once,

This is just for sample to get you idea how to do it .in this example i just used session variable to store entered data .

<form id="form1" runat="server">
  <table width="100%">
    <tr>
       <td>First Name</td>
       <td></td>
       <td>
           <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox></td>
    </tr>
    <tr>
      <td>Last Name</td>
      <td></td>
      <td>    <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox></td>
    </tr>
    <tr>
      <td colspan="3">
          <asp:button id="Button1" runat="server" text="Add" onclick="Button1_Click" xmlns:asp="#unknown" />
      </td>
    </tr>
  </table>
  <br />
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
</asp:gridview>

</form>



之后,您必须编写一些代码



after this you''ve to write some code

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("fname");
        dt.Columns.Add("lname");
        DataRow dr = dt.NewRow();
        dr[0] = "Murali";
        dr[1] = "krishna";
        dt.Rows.Add(dr);

        Session["TempData"] = dt;
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}
protected void Button1_Click(object sender, EventArgs e)
{
    DataTable dt = (DataTable)Session["TempData"];

    DataRow dr = dt.NewRow();
    dr[0] = TextBox1.Text;
    dr[1] = TextBox2 .Text ;
    dt.Rows.Add(dr);
    Session["TempData"] = dt;
    GridView1.DataSource = (DataTable)Session["TempData"];
    GridView1.DataBind();
}



在这里,我只是编写了此代码来进行测试,因此您必须对其进行修改以完全满足您的需求

最好的



Here i''m just made this code for testing you''ve to modify this to fullfill your requiremens

All the Best


这篇关于插入之前如何在gridview中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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