问题描述
我需要添加三个字段(国家名称,语言名称和描述)..
和一个添加按钮,仅使用表格或网格添加设计页面中的字段。如果我点击另一个按钮,即所有行创建的保存按钮应该存储在sql server 2005中..
我已经赚了30%现在我可以添加一行。如果我试图添加多行,它会覆盖。我能够找出原因但无法解决..Plz帮我完成这个过程...
这里我的代码是
I need to add three fields which of ( country name,language name and description )..
and a "add button" to add the fields in design page only using table or grid.If i click another button i.e "save button" that all the rows created are should be stored in sql server 2005..
I had made 30% of it now i can add a single row.if i tried to add multiple row it's overriding.I can able identify the reason but unable to solve.. Plz help me to complete this process...
Here my code's
protected void lnkbtnAddRow_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataColumn[] columns = { new DataColumn("Country", System.Type.GetType("System.String")), new DataColumn("Language", System.Type.GetType("System.String")), new DataColumn("Description", System.Type.GetType("System.String")) };
dt.Columns.AddRange(columns);
DataRow dr;
dr = dt.NewRow();
dr[0] = ddlCountry.SelectedValue;
dr[1] = ddlLanguage.SelectedValue;
dr[2] = txtDescription.Text;
dt.Rows.Add(dr);
GVaddrow.DataSource = dt;
GVaddrow.DataBind();
}
protected void lnkbtnSave_Click(object sender, EventArgs e)
{
}
Thanks in advance...
推荐答案
protected void lnkbtnAddRow_Click(object sender, EventArgs e)
{
if(Session["Data"]==null)
{
DataTable dt = new DataTable();
DataColumn[] columns = { new DataColumn("Country", System.Type.GetType("System.String")), new DataColumn("Language", System.Type.GetType("System.String")), new DataColumn("Description", System.Type.GetType("System.String")) };
dt.Columns.AddRange(columns);
}
else
{
DataTable dt=(DataTable)Session["Data"];
}
DataRow dr;
dr = dt.NewRow();
dr[0] = ddlCountry.SelectedValue;
dr[1] = ddlLanguage.SelectedValue;
dr[2] = txtDescription.Text;
dt.Rows.Add(dr);
Session["Data"]=dt;
GVaddrow.DataSource = dt;
GVaddrow.DataBind();
}
尝试这个...它应该有用...
问候
Dinesh Kumar.V。
Try this...It should work...
Regards
Dinesh Kumar.V.
这篇关于动态添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!