使用下拉菜单INSIDE GRIDVIEW的选定索引更改事件 [英] working with selected index change event of dropdown INSIDE GRIDVIEW
本文介绍了使用下拉菜单INSIDE GRIDVIEW的选定索引更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
gridview的代码如下.
< asp:GridView ID = " ShowFooter = " AutoGenerateColumns = " 错误"
runat = " >
<列>
< asp:TemplateField HeaderText = " >
< ItemTemplate>
< asp:DropDownList ID = " Width = " runat = " CssClass = "
AutoPostBack = " OnSelectedIndexChanged = " DropDownProducts_SelectedIndexChanged" DataSourceID = datasourceProducts" DataTextField = " DataValueField = " ProdId" </ asp:DropDownList >
< asp:SqlDataSource ID = " runat = " ConnectionString = "
SelectCommand = " </ >
</ ItemTemplate >
</ asp:TemplateField >
< asp:TemplateField HeaderText = " >
< ItemTemplate>
< asp:TextBox ID = " runat = " > </ asp:TextBox >
</ ItemTemplate >
</ asp:TemplateField >
< asp:TemplateField HeaderText = " >>
< ItemTemplate>
< asp:TextBox ID = " runat = " > </ asp:TextBox >
</ ItemTemplate >
< FooterStyle HorizontalAlign = " />
< FooterTemplate>
< asp:Button ID = " OnClick = " 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();
}
解决方案
ConnectionStrings:EasyCut%>" SelectCommand = " </ > </ ItemTemplate > </ asp:TemplateField > < asp:TemplateField HeaderText = " > < ItemTemplate> < asp:TextBox ID = " runat = " > </ asp:TextBox > </ ItemTemplate > </ asp:TemplateField > < asp:TemplateField HeaderText = " >> < ItemTemplate> < asp:TextBox ID = " runat = " > </ asp:TextBox > </ ItemTemplate > < FooterStyle HorizontalAlign = " /> < FooterTemplate> < asp:Button ID = " OnClick = " 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(); }
您好,
请看一下博客文章,也许它可以为您提供帮助:
http://asimsajjad.blogspot.in/2009/09/raising-dropdownlist.html [ ^ ]
类似的讨论:
http://stackoverflow.com/questions/5911874/dropdownlist-selectedindexchanged-within-gridview- [ ^ ]
http://stackoverflow. com/questions/463398/assign-an-event-to-a-custom-control-inside-a-repeater-control/463582#463582 [<asp:GridView ID="GridView1" ShowFooter="True" AutoGenerateColumns="False" runat="server" > <Columns> <asp:TemplateField HeaderText="Products/Services"> <ItemTemplate> <asp:DropDownList ID="DropDownProducts" Width="150px" runat="server" CssClass="RegistryDrop" AutoPostBack="true" OnSelectedIndexChanged="DropDownProducts_SelectedIndexChanged" DataSourceID="datasourceProducts" DataTextField="Name" DataValueField="ProdId"> </asp:DropDownList> <asp:SqlDataSource ID="datasourceProducts" runat="server" ConnectionString="<%$ ConnectionStrings:EasyCut %>" SelectCommand="SELECT [Name], [ProdId] FROM [tbl_ProdServ]"></asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Quantity"> <ItemTemplate> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </ItemTemplate> <FooterStyle HorizontalAlign="Right" /> <FooterTemplate> <asp:Button ID="ButtonAdd" OnClick="btn_add_Click" runat="server" Text="Submit" /> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView>
I tried following approach in the code behind but it doesnt seem to work
protected void DropDownProducts_SelectedIndexChanged(object sender, 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(); }解决方案ConnectionStrings:EasyCut %>" SelectCommand="SELECT [Name], [ProdId] FROM [tbl_ProdServ]"></asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Quantity"> <ItemTemplate> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </ItemTemplate> <FooterStyle HorizontalAlign="Right" /> <FooterTemplate> <asp:Button ID="ButtonAdd" OnClick="btn_add_Click" runat="server" Text="Submit" /> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView>
I tried following approach in the code behind but it doesnt seem to work
protected void DropDownProducts_SelectedIndexChanged(object sender, 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(); }
Hello,
Please have a look at the blog post, may be it can help you:
http://asimsajjad.blogspot.in/2009/09/raising-dropdownlist.html[^]
Similar discussions:
http://stackoverflow.com/questions/5911874/dropdownlist-selectedindexchanged-within-gridview-not-firing[^]
http://stackoverflow.com/questions/463398/assign-an-event-to-a-custom-control-inside-a-repeater-control/463582#463582[^]
这篇关于使用下拉菜单INSIDE GRIDVIEW的选定索引更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文