locked
radio button missing form label RRS feed

  • Question

  • User-944424728 posted

    Hello, I have a radio button and gridview. I can use this 2 line to clear out the first 2 radio button but when I add another row

    the id is ctl04 and will be ctl05.  I tried to add in the code behind but everything is not working. Please advise. thanks.

    // $('#ctl00_Main_content_grvPrimaryWorksite_ctl02_rbPrimary').attr('aria-labelledby', 'ctl00_Main_content_grvPrimaryWorksite');

    //$('#ctl00_Main_content_grvPrimaryWorksite_ctl03_rbPrimary').attr('aria-labelledby', 'ctl00_Main_content_grvPrimaryWorksite');  

    <asp:RadioButton ID="rbPrimary" runat="server" Checked='<%#Eval("primaryworksite")%>'

                                                onclick="javascript:RadioCheck(this);"/>

    --

    <asp:GridView Width="100%" ID="grvPrimaryWorksite" AllowPaging="true" AllowSorting="true"
    PageSize="5" BorderColor="White" runat="server" CellPadding="2" CellSpacing="0"
    AlternatingRowStyle-BackColor="#F2F2F2" AutoGenerateColumns="False" RowStyle-HorizontalAlign="Left"
    DataKeyNames="worksiteid" CssClass="datatable">

    --

    rb.Attributes.Add("aria-labelledby", grvPrimaryWorksite.ClientID)

    --

    For i As Integer = 0 To grvPrimaryWorksite.Rows.Count - 1

     

                Dim rb As New RadioButton

                rb = DirectCast(grvPrimaryWorksite.Rows(i).Cells(0).FindControl("rbPrimary"), RadioButton)

                If rb.Checked Then

                    rb.Attributes.Add("aria-labelledby", grvPrimaryWorksite.ClientID)

    Wednesday, November 20, 2019 3:24 PM

All replies

  • User1535942433 posted

    Hi,aspvbnet,

    According to your description, I couldn’t understand your requirement clearly.

     Could you please post the details aspx codes and the code-behind make up? 

    If you post more details information and codes, it will be more easily for us to reproduce your issue and find out the solution.

    Best regards,

    Yijing Sun

    Thursday, November 21, 2019 8:31 AM
  • User-944424728 posted

    aspx codes

    <asp:GridView Width="100%" ID="grvPrimaryWorksite" AllowPaging="true" AllowSorting="true"
    PageSize="5" BorderColor="White" runat="server" CellPadding="2" CellSpacing="0"
    AlternatingRowStyle-BackColor="#F2F2F2" AutoGenerateColumns="False" RowStyle-HorizontalAlign="Left"
    DataKeyNames="worksiteid" CssClass="datatable">
    <Columns>
    <asp:TemplateField HeaderText="<%$ Resources: Primary %>" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:RadioButton ID="rbPrimary" runat="server" CssClass="clsPrimary" Checked='<%#Eval("primaryworksite")%>'
    onclick="javascript:RadioCheck(this);" />
    <asp:HiddenField ID="hdPrimary" runat="server" Value='<%#Eval("worksiteid")%>' />
    </ItemTemplate>

    --code behind

    Protected Sub grvPrimaryWorksite_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvPrimaryWorksite.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then
    Dim rb As New RadioButton

    rb = CType(e.Row.Cells(0).FindControl("rbPrimary"), RadioButton)
    If rb.Checked Then

    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#CCCCCC")
    e.Row.Font.Bold = True

    End If

    Dim strWorkSiteCity As String = String.Empty
    Dim strWorkSiteState As String = String.Empty
    Dim strComma As String = ","

    Dim lblWorkSiteCity As New Label
    Dim lblWorkSiteState As New Label
    Dim lblComma As New Label

    '213287 validate values. Non US countries don't have states.
    strWorkSiteCity = Trim(DataTypeMapper.GSI_CString(DataBinder.Eval(e.Row.DataItem, "City")))
    strWorkSiteState = Trim(DataTypeMapper.GSI_CString(DataBinder.Eval(e.Row.DataItem, "State")))

    lblWorkSiteCity = CType(e.Row.Cells(2).FindControl("lblCity"), Label)
    lblWorkSiteState = CType(e.Row.Cells(2).FindControl("lblState"), Label)

    If strWorkSiteState <> String.Empty Then

    lblWorkSiteCity.Text = strWorkSiteCity & strComma
    lblWorkSiteState.Text = strWorkSiteState

    Else
    lblWorkSiteCity.Text = strWorkSiteCity
    lblWorkSiteState.Visible = False
    End If

    ElseIf e.Row.RowType = DataControlRowType.Pager Then

    If ds.Tables.Count > 0 Then
    TotalRows = ds.Tables(0).DefaultView.Count
    End If

    ucpgrPrimaryWorksite.TotalRows = TotalRows 'grvPrimaryWorksite.Rows.Count
    ucpgrPrimaryWorksite.PageCount = grvPrimaryWorksite.PageCount
    ucpgrPrimaryWorksite.PageSize = grvPrimaryWorksite.PageSize

    End If

    End Sub

    Friday, November 22, 2019 2:14 PM
  • User1535942433 posted

    Hi aspvbnet,

    I’m so sorry that I still couldn’t understand  what 'the radio button missing form label' means.

    Do you mean you want to modify the label style if the raidobutton is selected?

     Besides, you don’t post the codes which related with this codes :

      Dim rb As New RadioButton
    
                rb = DirectCast(grvPrimaryWorksite.Rows(i).Cells(0).FindControl("rbPrimary"), RadioButton)

    Could you please tell us where you call these codes?

    It will help us to understand your requirement more easily and  reproduce your issue and find out a solution.

    Best regards,

    Yijing Sun

    Monday, November 25, 2019 8:46 AM