Click here to Skip to main content
15,748,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
This needs to be done by having a radio button inside a grid view which it self is in repeater control.

The basic Logic is to have Radio Button with a single name under a different section of repeater control and Grid View control. That is achieved by using variable i, which is incremented a each looping of repeater control and grid view control.

Thanks
gsalunkhe

Here I am using a literal in .aspx page like this .
XML
<asp:repeater id="repFareDetail" runat="server" onitemdatabound="repFareDetail_ItemDataBound"
    onitemcreated="repFareDetail_ItemCreated" onitemcommand="repFareDetail_ItemCommand"
    oninit="repFareDetail_Init">
    /*This a row of repeater control*/
        <ItemTemplate>
            <table style="width: 100%; height: 100%; font-family: 'Arial Unicode MS'; border-right-style: solid;
                border-top-style: solid; border-left-style: solid; border-width: thin;" bgcolor="#E6F1F7">
                <tr align="center">
                    <td style="font-weight: bold;" class="style3">
                        <asp:Label ID="lblHeadFareType" runat="server" Text="Fare Type"></asp:Label>
                    </td>
<asp:gridview id="gdvDetails" runat="server" autogeneratecolumns="False" showheader="False"
    backcolor="#E6F1F7" style="width: 100%; height: 100%" bordercolor="#E6F1F7" visible="True"
    onrowcreated="gdvDetails_RowCreated">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                            /* This is a row of GridView control */
<td style="width: 5%;">
/*This is a Literal whcih is a place holder for code which I will be putting through by .cs file */
    <asp:literal id="RadioButtonMarkup" runat="server"></asp:literal>
</td>
</tr> </table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
        </ItemTemplate>
    </asp:repeater>




************* the .cs code ***********************

C#
protected void repFareDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            // A Class level variable which gets incremented at each loop of repeater control.
            i = i + 1;

            objServiceInteraction = clsUserInteractionFactory.GetServiceDetailResult();
            strItemValue = DataBinder.Eval(e.Item.DataItem, "PUBID").ToString();
            DataTable dt2 = objServiceInteraction.GetResultForDetail(strItemValue);

            GridView gvGridView = e.Item.FindControl("gdvDetails") as GridView;
            gvGridView.DataSource = dt2;
            gvGridView.DataBind();
        }
        catch (Exception expSearchResult)
        {
            Server.Transfer("~/Error/Error.aspx?ErrorMessage=" + expSearchResult.Message, false);
        }
    }
    
    protected void gdvDetails_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Literal output = (Literal)e.Row.FindControl("RadioButtonMarkup");
            /*Using the above value of i in name field*/
            output.Text = string.Format(@"<input name=""gpRadio{0}"" type=""radio"" />", i);
            /* You can pass a value also to this radio button which you may want to retirve after form is posted */
             value='<%# Eval("CategoryID") %>'
        }
    }
Posted
Updated 18-Jun-10 1:33am
v2
Comments
Ankur\m/ 18-Jun-10 7:32am    
Firstly, you have forgotten to mention the question.
Secondly, you have already asked a similar question (but there was a question in that.. :)).
And lastly you have not properly formatted the question.

I have taken care of last two. Could you please take care of the first one?
techno_manuj 5-Aug-10 7:43am    
Reason for my vote of 1
There is no question asked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900