我要訪問我的O1控制在我的GridView 這裏是使用此代碼訪問它在GridView如何找到在GridView控件
<asp:GridView ID="SelectedPollGridView" runat="server" Width="100%" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="PollID" DataSourceID="SelectedPollSqlDataSource" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<p class="text-center"><small><%#Eval("Header") %></small></p>
</HeaderTemplate>
<ItemTemplate>
<p class="text-right"><%#Eval("Body") %></p>
<div class="text-right">
<div runat="server" id="O1Div" visible='<%#Eval("O1Vis") %>' class="radio ">
<label>
<input class="pull-right" type="radio" name="optionsRadios" id="O1" value="option1">
<%#Eval("O1") %>
</label>
</div>
<div runat="server" id="O2Div" visible='<%#Eval("O2Vis") %>' class="radio">
<label>
<input class="pull-right" type="radio" name="optionsRadios" id="O2" value="option2">
<%#Eval("O2") %>
</label>
</div>
<div runat="server" id="O3Div" visible='<%#Eval("O3Vis") %>' class="radio">
<label>
<input class="pull-right" type="radio" name="optionsRadios" id="O3" value="option3">
<%#Eval("O3") %>
</label>
</div>
<div runat="server" id="O4Div" visible='<%#Eval("O4Vis") %>' class="radio">
<label>
<input class="pull-right" type="radio" name="optionsRadios" id="O4" value="option4">
<%#Eval("O4") %>
</label>
</div>
<asp:Button CssClass="btn btn-info" ID="SubmitPollButton" runat="server" Text="ثبت نظر" OnClick="SubmitPollButton_Click" />
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
和IM:
protected void SubmitPollButton_Click(object sender, EventArgs e)
{
System.Web.UI.HtmlControls.HtmlGenericControl O1Radio = (System.Web.UI.HtmlControls.HtmlGenericControl)SelectedPollGridView.Rows.FindControl("O1");
if (O1Radio.Attributes["checked"] == "checked")
{
Response.Redirect("somewhere");
}
}
但不起作用。 可以幫助我嗎? 在我的GridView中只有一個模板字段。這是否意味着我只有一行一格?
非常感謝。
在你試圖得到控制什麼方法? – Nacho
System.Web.UI.HtmlControls.HtmlGenericControl O1Radio =(System.Web.UI.HtmlControls.HtmlGenericControl)SelectedPollGridView.Rows [0] .FindControl(「O1」); –
添加'runat =「server」'標籤:' afzalulh