路过的DropDownList的值复制到GridView控件 [英] passing the value of dropdownlist into gridview
本文介绍了路过的DropDownList的值复制到GridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的数据库填充一个DropDownList,下面是我的code:
I have a dropdownlist populated by my database, below is my code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsNames"
DataTextField="Name" DataValueField="Id">
</asp:DropDownList>
<asp:SqlDataSource ID="dsNames" runat="server"
ConnectionString="<%$ ConnectionStrings:dbProfilesConnectionString %>"
SelectCommand="SELECT Lname+', '+Fname AS Name,Id FROM tblProfile">
</asp:SqlDataSource>
除了我DROPDOWNLIST,我有一个按钮及以下我有一个GridView,我要实现的是,每当我在DROPDOWNLIST选择姓名中的一个,然后当我点击按钮的名称应在GridView中添加。我使用asp.net使用C#。
Beside my Dropdownlist, I have a button and below I have a Gridview, what I want to achieve is whenever I select one of the name in my Dropdownlist, then when I click the button the name should be added in gridview. I am using asp.net with c#.
推荐答案
嘿试试这个code。
DataTable dttable = new DataTable();
DataColumn column;
DataRow row;
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "EmpName";
dttable.Columns.Add(column);
row = table.NewRow();
row["EmpName"] = DropDownList1.SelectedText;
dttable.Rows.Add(row);
Gridview1.DataSource = dttable;
Gridview1.DataBind();
在添加下一个记录,请保持会话或查看state.And与发挥数据表。
Before Adding next record please maintain datatable in Session or View state.And play with that.
希望它可以帮助你。
这篇关于路过的DropDownList的值复制到GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文