Community discussion forum

Set Radiobuttonlist value in datagrid during edit

  • 8 months ago

    Can anyone tell me what I'm doing wrong here? I keep getting "Object reference not set to an instance of an object." on the Edit line trying to set the value.  FYI - this is in a script tag NOT codebehind.  Thanks

     Datagrid:
    <asp:TemplateColumn HeaderText="News?" >
    <FooterTemplate><asp:RadioButtonList ID="radNews" Runat="Server" RepeatDirection="Horizontal"><asp:ListItem Text="True" Value="1" Selected="true" /><asp:ListItem Text="False" Value="0" /></asp:RadioButtonList></FooterTemplate>
    <ItemTemplate><%#Convert.ToBoolean(Container.DataItem("news"))%></ItemTemplate>
    <EditItemTemplate><asp:RadioButtonList ID="radNewsE" Runat="Server" RepeatDirection="Horizontal"><asp:ListItem Text="True" Value="1" /><asp:ListItem Text="False" Value="0" /></asp:RadioButtonList></EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="news" Visible="true" />

        Protected Sub dgList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs  ) Handles dgList.ItemCommand
            lblMsg.Text = String.Empty
            If e.CommandName = "Edit" Then
                dgList.EditItemIndex = e.Item.ItemIndex
                CType(dgList.Items(e.Item.ItemIndex).FindControl("radNewE"), RadioButtonList).SelectedValue = e.Item.Cells(13).Text
                CType(dgList.Items(e.Item.ItemIndex).FindControl("radNewE"), RadioButtonList).DataBind()
            End If

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).