本文介绍了使用下拉菜单INSIDE GRIDVIEW的选定索引更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格视图,该视图由DROPDOWN和每行2个文本框组成.单击按钮(在页脚处)后,应将第一行中的数据插入到DATABASE表中,并且必须创建新行.同样,无论何时在DDL中更改选定的索引,都必须使用DDL中选定项目的选定值填充该行中的相应文本框.对于在网格内部创建的每个新行应如何进行操作.gridview的代码如下.
< asp:GridView ID = " GridView1" ShowFooter = " 真实" AutoGenerateColumns = " 错误" runat = " 服务器" > <列> < asp:TemplateField HeaderText = " 产品/服务" > < ItemTemplate> < asp:DropDownList ID = " DropDownProducts" Width = " 150px" runat = " 服务器" CssClass = " RegistryDrop" AutoPostBack = " true" OnSelectedIndexChanged = " DropDownProducts_SelectedIndexChanged" DataSourceID = " datasourceProducts" DataTextField = " 名称" DataValueField = " ProdId" > </ asp:DropDownList > < asp:SqlDataSource ID = " datasourceProducts" runat = " 服务器" ConnectionString = " < %$ ConnectionStrings:EasyCut%>" SelectCommand = " 从[tbl_ProdServ]中选择[名称],[ProdId]" > </ asp:SqlDataSource > </ ItemTemplate > </ asp:TemplateField > < asp:TemplateField HeaderText = " 价格" > < ItemTemplate> < asp:TextBox ID = " TextBox2" runat = " 服务器" > </ asp:TextBox > </ ItemTemplate > </ asp:TemplateField > < asp:TemplateField HeaderText = " 数量" >> < ItemTemplate> < asp:TextBox ID = " TextBox3" runat = " 服务器" > </ asp:TextBox > </ ItemTemplate > < FooterStyle HorizontalAlign = " 右" /> < FooterTemplate> < asp:Button ID = " ButtonAdd" OnClick = " btn_add_Click" runat = " 服务器" Text = " 提交" /> </ FooterTemplate > </ asp:TemplateField > </ 列 > </ asp:GridView >
我尝试在后面的代码中遵循以下方法,但是它似乎不起作用
受保护的 无效 DropDownProducts_SelectedIndexChanged(对象发件人,EventArgs e) { TextBox box1 =(TextBox)GridView1.Rows [e.currentrow] .Cells [ 2 ].FindControl(" TextBox2"); DropDownList dl =(DropDownList)GridView1.Rows [e.currentrow] .Cells [ 2 ].FindControl(" DropDownProducts"); box1.Text = dl.SelectedValue.ToString(); }
解决方案
这篇关于使用下拉菜单INSIDE GRIDVIEW的选定索引更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!