你想从文本拳击手向行添加数据我到目前为止如何做到这一点我喜欢这样 这是我的网格视图`
<asp:GridView ID="GVDisplay" runat="server" AutoGenerateColumns="False"
BackColor="Silver" BorderColor="#660033" BorderStyle="Solid"
Height="211px" CellSpacing="1" Font-Bold="False"
Width="502px">
<Columns>
<asp:TemplateField HeaderText="Number of Mails">
<ItemTemplate>
<asp:TextBox ID="TXTno_ofmails" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="60px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="txtremarks" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="60px" />
</asp:TemplateField>
</asp:GridView>
这是我的C#代码 我有设计表单,我想从按钮单击
添加文本拳击手值到网格 protected void BtnAdd_Click(object sender, EventArgs e)
{
DataRow dr;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dr = dt.NewRow();
TxtNumOfMails.Text //My text box name
TxtRemarks.Text // My Text box name
dt.Rows.Add(dr);
GVDisplay.DataSource = dt;
GVDisplay.DataBind();
}
答案 0 :(得分:0)
试试此代码,请关闭列标记。
protected void btnsubmit_OnClick(object sender, EventArgs e)
{
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
DataRow dr = dt.NewRow();
dr["Column1"] = TxtNumOfMails.Text;
dr["Column2"] = TxtRemarksss.Text;
dt.Rows.Add(dr);
GVDisplay.DataSource = dt;
GVDisplay.DataBind();
}