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.DataSource = ds.Tables[0];
string k=ds.Tables[0].Rows[0][0].ToString();
gv1.DataBind();
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 = ((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();
foreach (GridViewRow row in gv1.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chk1");
if (chk.Checked)
{
TextBox2.Text = "kk";
}
}
}
public string getQnt()
{
string qnt = Request.QueryString["qnt"].ToString();
return qnt;
}
}
<%@ 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>
<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>