iT邦幫忙

0

'radiobutton' 未宣告。可能因為它的保護層級而導致無法存取。

阿薛 2017-10-24 10:38:2910311 瀏覽
  • 分享至 

  • xImage

請問各位大大,當我要使用gridview內的radiobuttonlist時,會出現以下錯誤:

'rdbtnLt1' 未宣告。可能因為它的保護層級而導致無法存取。

請問如何在vb.net的sub 呼叫gridview內的radiobuttonlist,程式碼如下:

gridview設計:

<asp:GridView ID="GridViewxxx" runat="server" AllowPaging="True" AllowSorting="true" AutoGenerateColumns="False" PageSize="5" CssClass="col-md-12 table table-bordered table-hover table-warning thtextShadow table-tr table-thcenter table-PagerStyle" Width="100%" DataKeyNames="StartID,ChkType,ChkSType,PChkResult,PChkTime,PChkCid,CChkResult,CChkTime,CChkCid,STypeID,TypeID,STypeNa,STypeStatus">
                <PagerSettings runat="server" Position="TopAndBottom" FirstPageText="第一頁" LastPageText="最後一頁" Mode="NumericFirstLast" />
                <PagerStyle runat="server" HorizontalAlign="Center" />
                <Columns runat="server">
                  <asp:BoundField DataField="stypena" HeaderText="XXX" HtmlEncode="true" ItemStyle-HorizontalAlign="Left" ReadOnly="true" />
                  <asp:TemplateField runat="server" HeaderText="XXX">
                    <HeaderStyle runat="server" Width="200px" />
                    <ItemTemplate runat="server">
                               <asp:RadioButtonList id="rdbtnLt1" runat="server">
            <asp:ListItem>通過</asp:ListItem>
            <asp:ListItem>不通過</asp:ListItem>
            <asp:ListItem>尚未檢核</asp:ListItem>           
                        </asp:RadioButtonList>
                      <asp:HiddenField ID="Hidpchkresult" runat="server" Value='<%# Bind("pchkresult") %>' />
                    </ItemTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="XXX">
                    <HeaderStyle Width="200px" />
                    <ItemTemplate>
       <asp:RadioButtonList id="rdbtnLt2" runat="server">
            <asp:ListItem>通過</asp:ListItem>
            <asp:ListItem>不通過</asp:ListItem>
            <asp:ListItem>尚未檢核</asp:ListItem>           
                        </asp:RadioButtonList>
                      <asp:HiddenField ID="Hidcchkresult" runat="server" Value='<%# Bind("cchkresult") %>' />
                        <asp:HiddenField ID="Hidchkstype" runat="server" Value='<%# Bind("chkstype") %>' />
                    </ItemTemplate>
                  </asp:TemplateField>
                  <asp:CommandField ShowSelectButton="True" Visible="false" />
                </Columns>
                <HeaderStyle CssClass="GridView_B_HeaderStyle" />
                <RowStyle CssClass="GridView_B_RowStyle" />
                <AlternatingRowStyle CssClass="GridView_B_AlternatingRowStyle" />
                <PagerStyle CssClass="aa" HorizontalAlign="Center" />
                <FooterStyle CssClass="GridView_B_FooterStyle" />
              </asp:GridView>

sub如下,呼叫不到gridview內的radiobuttonlist

 Public Sub save(ByRef cn As SqlConnection, ByRef startid As String)


            If rdbtnLt1.selected = False And Session("uchktype") = "p" Then
                MsgBox("請填入完整資訊")
            End If

            If rdbtnLt2.selected = False And Session("uchktype") = "c" Then
                MsgBox("請填入完整資訊")
            End If
            
end sub

請問如何呼叫gridview內的radiobuttonlist,謝謝各位大大。

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
baida0630
iT邦新手 4 級 ‧ 2017-10-24 13:56:45

Gridview中的物件操控跟給予值幾乎都是在RowCommand 和 RowDataBound執行

這篇你參考一下 應該能解決你的問題 點我

阿薛 iT邦新手 5 級 ‧ 2017-11-08 10:54:26 檢舉

問題已解決,程式碼如下,謝謝baida0630

Public Sub save(ByRef startid As String)
For i As Integer = 0 To GridViewxxx.Rows.Count - 1
Dim rdbtnLt1 As RadioButtonList = GridViewxxx.Rows(i).FindControl("rdbtnLt1")
Dim rdbtnLt2 As RadioButtonList = GridViewxxx.Rows(i).FindControl("rdbtnLt2")
Dim Hidchkstype As HiddenField = GridViewxxx.Rows(i).FindControl("Hidchkstype")
If rdbtnLt1.SelectedIndex <> 0 And rdbtnLt1.SelectedIndex <> 1 And rdbtnLt1.SelectedIndex <> 2 And Session("uchktype") = "p" Then
testrdl = "1"
End If
If rdbtnLt2.SelectedIndex <> 0 And rdbtnLt2.SelectedIndex <> 1 And rdbtnLt2.SelectedIndex <> 2 And Session("uchktype") = "c" Then
testrdl = "2"
End If
Next i
If Session("uchktype") = "c" And testrdl = "2" Then
MsgBox("請填入完整資訊")
Exit Sub
ElseIf Session("uchktype") = "p" And testrdl = "1" Then
MsgBox("請填入完整資訊")
Exit Sub
End If
End Sub
圓頭人 iT邦研究生 5 級 ‧ 2018-08-23 09:34:26 檢舉

路過提醒,如果baida0630 大大解決了您的問題
可以選為解答來結案哦~

我要發表回答

立即登入回答