Category Archives: RadioButton

[RESOLVED] RadioButtonList inside parent RadioButtonList

I am writing a form which has a set of options (radio buttons), and under each option, there is another set of options.  For example:

 - Session 1

      - New Book A

      - Used Book A

- Session 2

      - New Book B

      - Used Book B

I've tried using HTML <input type="radio", and <asp:RadioButton, but even though I assign the "name" attribute correctly, the buttons are not mutually exclusive -- i.e., you can click both within each group.  I see in "View Source" that the name and ID are altered, and therefore become ungrouped by the ASP.NET processing.

I've tried using <asp:RadioButtonList, and this works functionally, but the items are not grouped properly.  They appear like this:

- Session 1

- Session 2

      - New Book A

      - Used Book A

      - New Book B

      - Used Book B

I have not been able to find a solution to this problem, and would appreciate any help...

Thank you for responding.  The link you provided says, "Based on my research and experience, I think that it is impossible tocreate "nested radio button lists" using VS.NET"...

niksv

 http://bytes.com/topic/asp-net/answers/290891-nested-radiobuttonlists
 

I'm beginning to believe this, but it seems incredible to me that ASP.NET web forms cannot handle this.  I know this can be done with classic ASP (because I am converting an old web app which does this).  It also uses javascript to select the parent button if a child option is selected.  I will keep trying, and will post my result.


Please try this

//aspx
<form id="form1" runat="server">
    <div>
    

    </div>
    <br />
    <span>XXXXXXX</span>
    <br />
    <input id="RadioButtonList2_0" type="radio" name="RadioButtonList2" value="A" /><label for="RadioButtonList2_0">AAA</label>
    <br />
    <input id="Radio1" type="radio" name="RadioButtonList2" value="B" /><label for="RadioButtonList2_0">BBb</label>
    <br />
    <input id="Radio2" type="radio" name="RadioButtonList2" value="C" /><label for="RadioButtonList2_0">ccc</label>
    <br />
    <span>ZZZZZZZZ</span>
    <br />
    <input id="Radio3" type="radio" name="RadioButtonList2" value="D" /><label for="RadioButtonList2_0">ddd</label>
    <br />
    <input id="Radio4" type="radio" name="RadioButtonList2" value="E" /><label for="RadioButtonList2_0">eee</label>
    <br />
    <input id="Radio5" type="radio" name="RadioButtonList2" value="F" /><label for="RadioButtonList2_0">ffff</label>




    

    </form>


 

Thank you, but it's not really what I'm looking for.  I would like to put the parent radio buttons where you have the XXXXXXX and ZZZZZZZ text.  Also, I need to databind the parent radio buttons first.  When each parent item is created, I need to databind the corresponding child radio buttons based on a datakey from the parent datasource.


I could easily do something similar using ListViews, for example, using the parent ListView's ItemDataBound event to create a child ListView, but RadioButtonList does not have something like ItemDataBound.


I tried doing this using nested ListViews, and creating the individual radio buttons as HTML or ASP.NET server controls as described in my original post, but that (surprisingly) doesn't work because the "name" (HTML) or "GroupName" values I assign are not retained, and even though the page renders as I would like it to look, the radio buttons become ungrouped and useless.

Please refer this ([decker dong - msft]'s answer)  workaround here , for a similar situation like yours.

http://forums.asp.net/t/1458411.aspx

Hope this helps. 

Thank you, that does work for the scenario I posted.  

Unfortunately, I simplified my problem for posting, and ultimately, I need to place these radio buttons within a Repeater or ListView to produce additional layers and perform addition event handling.  I finally found that there is actually a bug in ASP.NET (http://support.microsoft.com/kb/316495) which prevents radio buttons from being mutually exclusive when used within a Repeater or ListView.  I've looked for a solution or workaround, but have not found one.  If you know of any, please let me know.  I am also going to ask for this in a new and separate thread.

Thanks again for your help!

[RESOLVED] Open a popup window to print after sql insert

What I want is to pop up a window that is 100 x 100 after I do a sql insert and then print the page.  In 1.1 it worked greate but in VS 2010 it seems not to work great always get errors.  So this is what I am doing.

When user clicks on submit it rotates through a gridview ans saves data to a sql table.  After this i want to open a small popup window and have the print options open with it, print the page and then it closes window on print.  Here is where I am having trouble, the popup always gives me errors, i am using an update panel and I don't know if this is the problem or not.

For Each row As GridViewRow In myGridAdmin.Rows
            Dim AQuesId As Integer = myGridAdmin.DataKeys(row.RowIndex).Value
            Dim Adata As TextBox = TryCast(row.FindControl("txtAData"), TextBox)
            Dim ARemarks As TextBox = TryCast(row.FindControl("txtARemarks"), TextBox)
            Dim ADtdate As TextBox = TryCast(row.FindControl("txtACal"), TextBox)
            Dim Aanswer As RadioButtonList = TryCast(row.FindControl("rblAdmin"), RadioButtonList)


            sql = "Insert tblSRpEventData (intPersonnelId, intUnitSRPId, intQuestionId, bitAnswer, strData, strRemarks, dtDoc, dtLogged, strlogged) VALUES (" & PersId & ", " & UnitID & ", " & AQuesId & ", " _
                    & "" & Aanswer.SelectedValue & ", '" & Adata.Text & "', '" & ARemarks.Text & "', '" & ADtdate.Text & "', '" & Date.Today & "', '" & userlogon & "')"


            insertUpdateDelete(sql)
        Next


        Dim ssn As String = PersId
 

        ClientScript.RegisterClientScriptBlock(Me.[GetType](), "open", "<script type='text/javascript' window.open('" + Request.ApplicationPath & "../Reports/SRpIsses.aspx?ID=" & ssn & "','Width=100,height=100');</script>")


 

kldeutsch

i am using an update panel

Try using ScriptManager instead.

ScriptManager.RegisterStartupScript(Page, Me.GetType(), "open",
                                    "window.open('" + Request.ApplicationPath & "../Reports/SRpIsses.aspx?ID=" & ssn & _
                                    "','Width=100,height=100');"True)

I am still getting an error when opening the link. this is where it point to. this is the source view of the code. <script type="text/javascript"> //<![CDATA[ (function() {var fn = function() {$get("ToolkitScriptManager1_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();window.open('/ReadinessTracker/Reports/SRpIssues2.aspx?ID=12','Width=100,height=100');//]]> <

Hi,

It seems that the window.open javascript is not correct.

kldeutsch

"<script type='text/javascript' window.open('" + Request.ApplicationPath & "../Reports/SRpIsses.aspx?ID=" & ssn & "','Width=100,height=100');</script>

It should be:

<script type='text/javascript'> window.open('" + Request.ApplicationPath & "../Reports/SRpIsses.aspx?ID=" & ssn & "','PopWindow','Width=100,height=100');</script>

Also you can try this:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim url As String = Request.ApplicationPath & "../Reports/SRpIsses.aspx?ID=" & ssn
        Dim Script As String = "window.open('" + url + "', 'Popup', 'height=100,width=100');"

        Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), "PopWindow", Script, True)
        'The button isn't in updatpanel

        ScriptManager.RegisterStartupScript(Page, Me.GetType(), "PopWindow", Script, True)
        'The button in updatpanel
    End Sub

 

Hope this can help you.

[RESOLVED] I want to add counting number to radiobuttonlist items.How should i do that

Hi,

I want to add counting number to radiobuttonlist items, the radiobuttonlist is databounded.

    protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
       
        RadioButtonList rbl = e.Item.FindControl("rblAnswer") as RadioButtonList;
        rbl.DataTextField ="AnswerText";
        rbl.DataValueField = "AnswerID";
        rbl.DataSource = BindAnswer(questionid);
        rbl.DataBind();
    }

tanx

sepid

One way is adding the Number in code behind using RadioButtonList DataBound event and another way is using Row_Number() function in your SELECT query.

protected void rblAnswer_DataBound(object sender, EventArgs e)
{
    RadioButtonList rblAnswer = (RadioButtonList)sender;
    foreach (ListItem item in rblAnswer.Items)
    {
        item.Text = string.Format("{0}.{1}", rblAnswer.Items.IndexOf(item) + 1, item.Text);
    }
}

Add OnDataBound="rblAnswer_DataBound" for the RadioButtonList in the repeater ItemTemplate. That's it.

[RESOLVED] How to find a dynamically built control in asp.net web page

In my one asp.net web page by VS 2008 I dynamically creates a set of RadioButtonList and TextBox by objects

Dim

rdoList As RadioButtonList = New RadioButtonList() with rdoList.ID = "rdoTask" & ID

Dim

 

txtComment As TextBox = New TextBox() with  txtComment.ID = "txtComment" & ID

 ID depending on DataRow count number and add these objects to TableCell which is added to TableRow which is added to

<

 

asp:Table ID="tblTaskStandards" runat="server"> set on the aspx file.

The current issue is I can load the web page with a set of RadioButtonLists and TextBoxs but can't find the these dynamically built controls by Me.FindControl("rdoTask" & ID) in aspx.vb file to save info assigned to these controls.

How to solve this issue ? Thanks a lot in advance!



 

Re-create the controls (using the same original ID) on EVERY postback, and you shouldbe able to use findcontrol() after that.

Thank you for the message. In order to post back, what shouls I do in the code?

A postback occurs usually as a result of some event taking place on the page like a button click, or a slection from a dropdownlist, or text changed in a textbox.  So you must have something on your form that's raising an event like a button click for instance; that's going to cause a postback.

[RESOLVED] GridView-required Field and regular expressions validator Issues...

Hi I have a website created in asp.net and have the following fields displayed in the grid view linked through a database.

  • <div> <div>

    First_Name   Last_name  City Username  Password Email Mobile Gender

    please let me how I can put validations when the edit button is clicked and the textboxs popout...

    I have tried a lot of ways like edit template and all but they have not been helpful

    Really need urgent help..If you need I can also post the code I am using..

    Thanking in advance..

    </div> </div>

The code I have written till now goes like this :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView.aspx.cs" Inherits="GridView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Grid View</title>
    
    
    
    <style type="text/css">
        #form1
        {
            height: 974px;
        }
        .style1
        {
        }
        #hidr
        {
            height: 23px;
            width: 51px;
        }
    </style>
</head>
<body style="text-align: center; background-color: #993366">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="356px"
        Width="360px" onselectedindexchanged="GridView1_SelectedIndexChanged"
        BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
        CellPadding="3" CellSpacing="2"
        onrowupdated="GridView1_RowUpdated">
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <Columns>

            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
                        CommandName="Update" Text="Update"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                        <%--<asp:TextBox ID="TextBox13" runat="server" ></asp:TextBox>--%>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                        CommandName="Edit" Text="Edit"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="First_Name" HeaderText="First_Name"
                SortExpression="First_Name" />
            <asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
                SortExpression="Last_Name" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="Username" HeaderText="Username"
                SortExpression="Username" />
            <asp:BoundField DataField="Password" HeaderText="Password"
                SortExpression="Password" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Mobile" HeaderText="Mobile"
                SortExpression="Mobile" />
            <asp:BoundField DataField="Gender" HeaderText="Gender"
                SortExpression="Gender" />
        </Columns>
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <EmptyDataTemplate>
            &nbsp;
        </EmptyDataTemplate>
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    <br />
    <asp:Button ID="Button" runat="server" onclick="Button_Click" Text="Insert" />
        <b>&nbsp;&nbsp;<asp:Button ID="Button1" runat="server"
        onclick="Button1_Click" Text="Go Back" />
    &nbsp;&nbsp; </b><asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        DeleteCommand="DELETE FROM [entered] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [entered] ([First_Name], [Last_Name], [City], [Username], [Password], [Email], [Mobile], [Gender]) VALUES (@First_Name, @Last_Name, @City, @Username, @Password, @Email, @Mobile, @Gender)"
        SelectCommand="SELECT * FROM [entered]"
        UpdateCommand="UPDATE [entered] SET [First_Name] = @First_Name, [Last_Name] = @Last_Name, [City] = @City, [Username] = @Username, [Password] = @Password, [Email] = @Email, [Mobile] = @Mobile, [Gender] = @Gender WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Decimal" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="First_Name" Type="String" />
            <asp:Parameter Name="Last_Name" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Username" Type="String" />
            <asp:Parameter Name="Password" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Mobile" Type="Decimal" />
            <asp:Parameter Name="Gender" Type="String" />
            <asp:Parameter Name="ID" Type="Decimal" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="First_Name" Type="String" />
            <asp:Parameter Name="Last_Name" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Username" Type="String" />
            <asp:Parameter Name="Password" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Mobile" Type="Decimal" />
            <asp:Parameter Name="Gender" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <div id="inputForm" style="height: 543px" visible="true" runat="server">
      <br />
        Fi<b>rst Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox1" runat="server" MaxLength="30"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel2" runat="server" Text="Last Name"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox2" runat="server" MaxLength="20"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel8" runat="server" Text="Username"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox6" runat="server" MaxLength="15"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
            ControlToValidate="TextBox6" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel9" runat="server" Text="Password"></asp:Label>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox9" runat="server" MaxLength="15"
            style="margin-top: 8px" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
            ControlToValidate="TextBox9" ErrorMessage="Required field">Required field</asp:RequiredFieldValidator>
        <br />
        <br />
        </span>
        <asp:Label ID="myLabel3" runat="server" Text="City"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox3" runat="server" MaxLength="25"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
            ControlToValidate="TextBox3" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </span>
        <asp:Label ID="myLabel4" runat="server" Text="Email address"></asp:Label>
        &nbsp;&nbsp; <span class="style1">
        <asp:TextBox ID="TextBox4" runat="server" MaxLength="25"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="TextBox4" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
        runat="server" ErrorMessage="Invalid Email"
        
        
        
        
            ValidationExpression="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.in))$"
            ControlToValidate="TextBox4"></asp:RegularExpressionValidator>
        <br />
        <br />
        </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
        <asp:Label ID="myLabel6" runat="server" Text="Mobile No."></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style1">
        <asp:TextBox ID="TextBox5" runat="server" MaxLength="10"
            ontextchanged="TextBox5_TextChanged"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="TextBox5" ErrorMessage="Required Field">Required Field</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="Validator1" runat="server"
            ControlToValidate="TextBox5" Text="Please enter only numbers"
            ValidationExpression="[0-9]{6,}"></asp:RegularExpressionValidator>
            
            <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" language="javascript">
        $(document).ready(function(){
    
    //called when key is pressed in textbox
    $("#TextBox5").keypress(function (e)  
    {
      //if the letter is not digit then display error and don't type anything
      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
      {
        //display error message
        $("#errmsg").html("Digits Only").show().fadeOut("slow");
        alert("Only Nos are allowed");
        return false;
      }    
    });

  });
  </script>  
        <br />
        <br />
        <asp:Label ID="myLabel5" runat="server" style="text-align: left"
            Text="Choose Gender"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
            Height="63px">
            <asp:ListItem Selected="True">Male</asp:ListItem>
            <asp:ListItem>Female</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <asp:Literal ID="litmsg" runat="server" Text="" Visible="false" />
        <br />
        <br />
        
        <asp:Button ID="myButton2" runat="server" Height="24px"
            onclick="myButton2_Click" Text="Create" />
        &nbsp;</b><span class="style1"></div>
    </form>
</body>
</html>