Click here to Skip to main content
16,004,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In gridview i have 4 radio buttons in each row,each row i want to select only one radio button this is possible by using asp:radio button by groupname in html it being meaning less,but when i select the radio button in each row it has to contain a value after clicking the button i want to appear that all values which are having radio buttons....pls solve my problem thank u in adv.....kishore



this is my design and code..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
public partial class GetBOM : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("server= RND3-12\\MSSQLEXPDB; User id=sa;password=prayoglabs@123; database=IMS");
    string sv1,sv2,sv3,sv4;
    public static int count = 0;
    public static int GEtId()
    {
        count++;
        return count;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string s = "select B.item_id, B.item_quantity,I.Item_Id,I.Item_Description,I.Item_Make_Id,I.Item_Price1,I.Item_Price2,I.Item_Price3,I.Item_Price4,M.make_id,M.make_Name  from BomDetails B, ItemDetails I,Make M where B.Item_id=I.Item_Id and I.Item_Make_Id=M.make_id ";
        SqlDataAdapter da = new SqlDataAdapter(s, con);
        DataSet ds = new DataSet();
        da.Fill(ds, "ItemDetails");
        //gv1.Dispose();
        gv1.DataSource = ds.Tables[0];
        string k=ds.Tables[0].Rows[0][0].ToString();
        gv1.DataBind();
        //gv1.Dispose();
        if (Page.IsPostBack == false)
        {
            count = 0;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < gv1.Rows.Count; i++)
        {
            GridViewRow r = gv1.Rows[i];
            //bool ischecked = ((RadioButton)r.FindControl("rb1")).Checked;
            bool ischecked = ((CheckBox)r.FindControl("chk1")).Checked;
            bool schecked = ((CheckBox)r.FindControl("chk2")).Checked;
            if (schecked)
            {
                sb.Append(gv1.Rows[i].Cells[3].Text);
            }
        }
        TextBox1.Text=sb.ToString();
            //sv1 = Request.Form["rd1"];
            //TextBox1.Text=sv1;
            //sv2 = Request.Form["rd2"];
            //TextBox2.Text = sv2;
            //  GridViewRow r = gv1.FooterRow;
        foreach (GridViewRow row in gv1.Rows)
         {
         CheckBox chk = (CheckBox)row.FindControl("chk1");
            //RadioButton rdb1 = (RadioButton)row.FindControl("rb1");
            //RadioButton rdb2 = (RadioButton)row.FindControl("rb2");
            //RadioButton rdb3 = (RadioButton)row.FindControl("rb3");
            //RadioButton rdb4 = (RadioButton)row.FindControl("rb4");
           if (chk.Checked)
           {
             TextBox2.Text = "kk";
           }
            //if (rdb1.Checked)
            //{
            //   TextBox1.Text  = rdb1.Checked.ToString();
            //}
            //if (rdb2.Checked)
            //{
            //    TextBox2.Text = rdb2.Checked.ToString();
            //}
            //if (rdb3.Checked)
            //{
            //    TextBox3.Text = rdb3.Checked.ToString();
            //}
            // if (rdb4.Checked)
            //{
            //    TextBox3.Text = rdb4.Checked.ToString();
            //}
        //}
        //for (int i = 0; i < gv1.Rows.Count; i++)
        //{
        //    RadioButton rb = (RadioButton)gv1.FindControl("rd1");
        //    if (rb.Checked)
        //    {
        //        GridViewRow row = (GridViewRow)rb.Parent.Parent;
        //        TextBox1.Text=gv1.Rows[0][
        //    }
       }
    }
    public string getQnt()
    {
        string qnt = Request.QueryString["qnt"].ToString();
        return qnt;
    }
    //protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
    //{
    //    for (int i = 0; i < gv1.Rows.Count; i++)
    //    {
    //        RadioButton rb =(RadioButton)gv1.FindControl("rd1");
    //        if (rb.Checked)
    //        {
    //          GridViewRow row =(GridViewRow)rb.Parent.Parent;
    //        }
    //    }
    //}
}


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

<!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">
<script type="text/javascript">
    function rchk() {
        var id = document.getElementsByName("rd2").value;
        return id;
    }
</script>
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
     <table cellpadding="4" cellspacing="4">
       <asp:GridView ID="gv1" runat="server" AutoGenerateColumns="False" >
        <Columns>
        <asp:TemplateField>
        <HeaderTemplate>
        <th align="center" rowspan="2">Item Description</th>
        <th align="center" colspan="2">Quantity Per</th>
        <th align="center" colspan="3">Make1</th>
        <th align="center" colspan="3">Make2</th>
        <th align="center" colspan="3">Make3</th>
        <th align="center" colspan="3">Make4</th>
        <tr>
        <th>Sno</th>
         <th align="center">Req Qnt</th>
        <th align="center">Prod Qnt</th>
        <th align="center">If YES</th>
        <th align="center">Make</th>
        <th align="center">P/U</th>
        <th align="center">If YES</th>
        <th align="center">Make</th>
        <th align="center">P/U</th>
        <th align="center">If YES</th>
        <th align="center">Make</th>
        <th align="center">P/U</th>
        <th align="center">If YES</th>
        <th align="center">Make</th>
        <th align="center">P/U</th>
        </tr>

        </HeaderTemplate>

         <ItemTemplate>
         <%#GEtId() %>
         <td><%#Eval("Item_Description")%></td>
         <td><%#Eval("item_quantity")%></td>
         <td><%# getQnt() %></td>

        <td><asp:RadioButton  ID="rb1" GroupName="g1" runat="server" ></asp:RadioButton>
        <asp:CheckBox ID="chk1" runat="server"  />
        <%--<input name="rd1" type="radio" value='<%#Eval("Item_Price1")%>' />--%>
        </td>
        <td><%#Eval("make_Name")%></td>
        <td><%#Eval("Item_Price1")%></td>


        <td><asp:CheckBox ID="chk2" runat="server"  />
        <%--<input name="rd2" value='<%#Eval("Item_Price1")%>' type="radio"  onclick="rchk()"  />--%>
        <asp:RadioButton  ID="rb2" GroupName="g1" runat="server" ></asp:RadioButton></td>
        <td><%#Eval("make_Name")%></td>
        <td><%#Eval("Item_Price2")%></td>


        <td><%--<input name="rd3" type="radio" value='<%#Eval("Item_Price1")%>' />--%>
        <asp:CheckBox ID="chk3" runat="server"  />
        <asp:RadioButton  ID="rb3" GroupName="g1" runat="server" ></asp:RadioButton></td>
        <td><%#Eval("make_Name")%></td>
        <td><%#Eval("Item_Price3")%></td>


        <td><%--<input name="rd4" type="radio" value='<%#Eval("Item_Price1")%>' />--%>
        <asp:CheckBox ID="chk4" runat="server"  />
        <asp:RadioButton  ID="rb4" GroupName="g1" runat="server" ></asp:RadioButton></td>
        <td><%#Eval("make_Name")%></td>
        <td><%#Eval("Item_Price4")%></td>


       </ItemTemplate>
       </asp:TemplateField>
        </Columns>
        </asp:GridView>
           </table>
         </div>
         <p>
&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="Label1" runat="server" Text="Label"></asp:Label>
             <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
             <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
             <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"  />
    </p>
         </form>
        </body>
        </html>
Posted
Updated 19-Apr-11 23:22pm
v3
Comments
Prerak Patel 20-Apr-11 5:22am    
Don't repost the question, you can modify the previous one. This time I am doing it for you.

1 solution

try this way,filter out what you want

Request.Form.AllKeys
 
Share this answer
 

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