2016-07-25 62 views
0

我有一個GridView控件,其中包含一個包含數據綁定RadioButtonList的列。 RBL正確綁定到其DataTable,但沒有顯示在GridView中。在標記中添加ListItems確實顯示,並顯示Label控件 - 我只是將這兩個做爲測試。有沒有人看到我失蹤?數據綁定RadioButtonList綁定,但現在顯示在GridView中

TIA任何幫助。 邁克

標記:

<asp:TemplateField HeaderText="Preset Text" HeaderStyle-HorizontalAlign="Center"> 
    <ItemTemplate> 
     <asp:RadioButtonList ID="rblPresetText" runat="server" DataValueField="pKey" DataTextField="Contents" GroupName="PresetText" RepeatDirection="Vertical"></asp:RadioButtonList> 
    </ItemTemplate> 
</asp:TemplateField> 

代碼隱藏:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load 

     GlobalVar.LoadData(Session("UserPKey")) 
     Header1.ConnectionStr = GlobalVar.ConnectString 
     Header1.HDLawFirm = GlobalVar.LawFirmDir 

     If Page.IsPostBack = False Then        
      FillNotesDataSet() 
      BindNotesGrid() 
      BindPresetTextRadioButtonList() 
     End If 

    End Sub 

Protected Sub BindPresetTextRadioButtonList() 

     Dim DAL As New DataAccessLayer 
     Dim dtPresetText As New DataTable 
     Dim rblPresetText As New RadioButtonList 

     dtPresetText = DAL.GetTextPickerTextForUser(Session("ClientKey"), Session("UserPKey")) 

     rblPresetText.DataSource = dtPresetText 
     rblPresetText.DataBind() 

    End Sub 
+0

是否檢查'dtPresetText'是不是空的? – Andrei

+0

是的,它有13行,我甚至可以在綁定後立即從DDL中獲取值。 – Mike

回答

1

你聲明的單選按鈕列表中一個TemplateField,但不用檢索的每一行控制,將創建一個可以填充一個新的單選按鈕列表。由於該新控件未包含在任何容器或GridView中,因此它不會顯示在頁面上。

你可以在GridView的RowDataBound事件處理程序的模板列的單選按鈕列表和數據綁定到控件:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     RadioButtonList rblPresetText = e.Row.FindControl("rblPresetText") as RadioButtonList; 

     // Bind the data to the RadioButtonList 
     ... 
    } 
} 
+0

啊,那個工作很好。非常感謝@ConnorsFan! – Mike