我有一个带有模板列的gridview,我想将每个定义列的文本框值发送到gridview。我尝试过打击代码,但列显示为双重。我使用telerik控件进行gridview
<telerik:RadGrid ID="RadGrid1" runat="server">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="BrandName"
HeaderText="Brand Name" UniqueName="BrandName"
<HeaderStyle Width="170px" />
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
后端代码
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dt = new DataTable();
MakeDataTable();
}
else
{
dt = (DataTable)ViewState["DataTable"];
}
ViewState["DataTable"] = dt;
}
private void MakeDataTable()
{
dt.Columns.Add("BrandName");
}
private void AddToDataTable()
{
DataRow dr = dt.NewRow();
dr["BrandName"] = brandname.Text;
dt.Rows.Add(dr);
}
private void BindGrid()
{
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
AddToDataTable();
BindGrid();
}
上面的代码在点击时显示2列