2016-07-25 101 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