在datalist的ITem模板中如何取到添加控件(比如一个textbox)的值,麻烦了。哦用C# [已结帖,结帖人:zergfoot]
编程论坛 楼主 实在是搞不定了。麻烦给讲讲。 aspx文件: <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> 题号: <asp:Label ID="idLabel" runat="server" Text=' <%# Eval("id") %>'> </asp:Label> <br /> 问题: <asp:Label ID="questionLabel" runat="server" Text=' <%# Eval("question") %>'> </asp:Label> <br /> A: <asp:Label ID="answer1Label" runat="server" Text=' <%# Eval("answer1") %>'> </asp:Label> <br /> B: <asp:Label ID="answer2Label" runat="server" Text=' <%# Eval("answer2") %>'> </asp:Label> <br /> C: <asp:Label ID="answer3Label" runat="server" Text=' <%# Eval("answer3") %>'> </asp:Label> <br /> D: <asp:Label ID="answer4Label" runat="server" Text=' <%# Eval("answer4") %>'> </asp:Label> <br /> <asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem>A </asp:ListItem> <asp:ListItem>B </asp:ListItem> <asp:ListItem>C </asp:ListItem> <asp:ListItem>D </asp:ListITem> &nb
sp; </ASP:RadioButtonList> </ItemTemplate> .cx文件: protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { String select; RadioButtonList one = (RadioButtonList)DataList1.FindControl("RadioButtonList1"); select = one.SelectedItem.Text; Response.WrITe(select); }实在是不知道怎么取RadioButtonList1的值。
编程论坛 1 个网友回答: 找到解决办法,原来要用 selectRBL = (RadioButtonList)DataList1.Controls[i].FindControl("RadioButtonList1");//i为模板的具体行数 selectValue[i] = selectRBL.SelectedITem.Value.ToString(); 这样才能取到值
欢迎转载,但请保留出处,本文章转自[华软网] 原文链接:http://www.huarw.com/program/net/aspnet/200810/1627525_2.html