如何在网格视图中添加行 [英] HOW Add row in grid view

查看:78
本文介绍了如何在网格视图中添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:GridView ID="showinfogrid" runat="server" AutoGenerateColumns="False"

    Width="100%">
           <Columns>
            <asp:BoundField DataField ="Name" HeaderText ="Employee_Name" ReadOnly="true" />
            <asp:BoundField DataField ="Employee_ID" HeaderText ="Emp_ID" ReadOnly="true"/>
            <asp:BoundField DataField ="Department" HeaderText ="Department" ReadOnly="true"/>
            <asp:BoundField DataField ="Designation" HeaderText ="Designation" ReadOnly="true"/>
           </Columns>
       </asp:GridView>



这是按钮中的click事件


this is the click event in the button

protected void Button1_Click(object sender, EventArgs e)
{
    dept.Text=Deptdrop.SelectedItem.Text;
    desLabel.Text = Desigdrop.SelectedItem.Text;
    DataTable dt = new DataTable();
    this.showinfogrid.Visible = true;
    dt.Columns.Add("Name");
    dt.Columns.Add("Employee_ID");
    dt.Columns.Add("Department");
    dt.Columns.Add("Designation");
    dt.Rows.Add(nameTextBox1.Text.Trim(), empidTextBox2.Text.Trim(), Deptdrop.SelectedItem.Text, Desigdrop.SelectedItem.Text);
    showinfogrid.DataSource = dt;
    showinfogrid.DataBind();

}



任何人告诉我如何在网格视图中每次添加行时单击按钮而不刷新页面但是新行添加在上一行之后。


Anyone tell me how i add row each time in the grid view when i click button without refreshing the page but the new row add after the previous row.

推荐答案

查看此链接:从ASP.NET GridView动态添加和删除行 [ ^ ]。这就是你要找的东西。



此外,正如 Karthik [ ^ ],将代码包装在更新面板中。
See this link : Dynamically adding and deleting rows from ASP.NET GridView[^]. It is all about what you are looking for.

Further,as suggested by Karthik[^],wrap your code inside update panel.


查看本教程:



http: //www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx [ ^ ]



为防止页面被刷新,请将gridview添加到UpdatePanel控件中。



http://msdn.microsoft。 com / en-us / library / bb399001.aspx [ ^ ]
Check up this tutorial:

http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx[^]

To prevent page from being refreshed, add the gridview into UpdatePanel control.

http://msdn.microsoft.com/en-us/library/bb399001.aspx[^]


使用以下代码在gridview中添加新行。





Use the below code to add the new row in gridview.


//showinfogrid.Rows[0].Cells.Clear();//clear the gird data
showinfogrid.Rows[0].Cells.Add(new TableCell()); 
showinfogrid.Rows[0].Cells[0].ColumnSpan = TotalColumns;// to merge
showinfogrid.Rows[0].Cells[0].Text = "No Record Found";


这篇关于如何在网格视图中添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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