Hi
I had two values inside foreach loop I.e
for each(GridViewRow grow in GridViewdetails.Rows)
{
string dd=grow.cells[4].Text
string cc=grow.cells[5].Text
}
What I want is on button click these two value should show in another gridview or datalist
//-----------------------------------Second Gridvew To Show Data Of Selected Radio Button On Button Click —------------------------------------------------—
<asp:GridView ID="Gridshow" runat="server"></asp:GridView>
//----------------------------------------------------C# Code To Get the Selected Radiobutton Value on Second Grid on Button Click--------------------------------------------------//
Hi ,
a2h
Error is resolved but still having one problem that
When I bind the dt to gridview it's showing only the last selected radio button coulmn value
Because the previous values are not saving in datatable
Can you tell me how to add my values in dt
And after all values added to datatable then it assign to gridview
When I bind the dt to gridview it's showing only the last selected radio button coulmn value
Because the previous values are not saving in datatable
Can you tell me how to add my values in dt
And after all values added to datatable then it assign to gridview
You might consider saving the values to database when user selects a row and then populate the gridview from database.
Member
18 Points
83 Posts
Show values in gridview ,Datalist in asp.net
Dec 07, 2016 05:29 PM|satyam khare|LINK
I had two values inside foreach loop I.e
for each(GridViewRow grow in GridViewdetails.Rows)
{
string dd=grow.cells[4].Text
string cc=grow.cells[5].Text
}
What I want is on button click these two value should show in another gridview or datalist
All-Star
50831 Points
9895 Posts
Re: Show values in gridview ,Datalist in asp.net
Dec 07, 2016 06:36 PM|A2H|LINK
You can try with the below implemenation
HTML
Aje
My Blog | Dotnet Funda
Member
18 Points
83 Posts
Re: Show values in gridview ,Datalist in asp.net
Dec 08, 2016 04:45 AM|satyam khare|LINK
Hi,
Am Getting Some Error, Here is my Code
//------------------------------------------------------------------------FirstGridView------------------------------------------------//
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" Width="995px" algin="center" CssClass="mydatagrid" PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" OnRowDataBound=" GridView2_RowDataBound" OnPreRender="GridView2_PreRender">
<Columns>
<asp:BoundField DataField="Student_Reg_No" HeaderText="Roll No" ItemStyle-Width="8%"
SortExpression="LastName">
<ItemStyle Width="8%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Present" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:RadioButton ID="rbpresent" runat="server" GroupName="checked" Checked="true" onclick="setrowcolorpresent(this);" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Absent" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:RadioButton ID="rbabsent" runat="server" GroupName="checked" onclick="setrowcolorabsent(this);" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Leave" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:RadioButton ID="ableave" runat="server" GroupName="checked" onclick="setrowcolorLeave(this);" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="ADM_NO"
HeaderText="Admission No"
SortExpression="FirstName" ItemStyle-Width="11%">
<ItemStyle Width="11%" />
</asp:BoundField>
<asp:BoundField DataField="Student_Name" HeaderText="Student Name"
SortExpression="FirstName" ItemStyle-Width="27%">
<ItemStyle Width="27%" />
</asp:BoundField>
<asp:BoundField DataField="Class" HeaderText="Class"
SortExpression="FirstName" ItemStyle-Width="6%">
<ItemStyle Width="6%" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="FirstName" ItemStyle-Width="6%">
<ItemStyle Width="6%" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Fathers_Name" HeaderText="Fathers Name."
SortExpression="FirstName" ItemStyle-Width="15%">
<ItemStyle Width="15%" />
</asp:BoundField>
<%--<asp:BoundField DataField="SmsDetailMobNo" HeaderText="Mob No."
SortExpression="FirstName" ItemStyle-Width="15%" DataFormatString="######"/>--%>
<asp:BoundField DataField="SmsDetailMobNo" HeaderText="Mob No." HtmlEncode="False"
SortExpression="FirstName" ItemStyle-Width="9%">
<ItemStyle Width="9%" HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="header" />
<PagerStyle CssClass="pager" />
<RowStyle CssClass="rows" BackColor="#4CAF50" />
</asp:GridView>
//-----------------------------------Second Gridvew To Show Data Of Selected Radio Button On Button Click —------------------------------------------------—
<asp:GridView ID="Gridshow" runat="server"></asp:GridView>
//----------------------------------------------------C# Code To Get the Selected Radiobutton Value on Second Grid on Button Click--------------------------------------------------//
[System.Web.Services.WebMethod]
protected void btnsemdsms_Click(object sender, EventArgs e)
{
if(TextMain.Text == "" || TextPreview.Text == "")
{
}
else
{
try
{
string strAdmissionNO = string.Empty;
string StuName = string.Empty;
string strname = string.Empty;
foreach (GridViewRow gvrow in GridView2.Rows)
{
RadioButton chkabsent = (RadioButton)gvrow.FindControl("rbabsent");
RadioButton chkleave = (RadioButton)gvrow.FindControl("ableave");
RadioButton chkpresent= (RadioButton)gvrow.FindControl("rbpresent");
if (chkabsent != null & chkabsent.Checked)
{
gvrow.BackColor = ColorTranslator.FromHtml("Red");
strAdmissionNO = gvrow.Cells[4].Text + ",";
string output = strAdmissionNO.Trim(",".ToCharArray());
GridViewRow row = (GridViewRow)((RadioButton)sender).NamingContainer;
DataTable dt = new DataTable("sample");
dt.Columns.Add("ADM_NO");
dt.Columns.Add("Student_Name");
DataRow dataRow;
dataRow = dt.NewRow();
//Change the column index here
dataRow[0] = row.Cells[1].Text;
dataRow[1] = row.Cells[2].Text;
dt.Rows.Add(dataRow);
Gridshow.DataSource = dt;
Gridshow.DataBind();
}
else if (chkleave != null & chkleave.Checked)
{
gvrow.BackColor = ColorTranslator.FromHtml("#f9a825");
}
else if (chkpresent != null & chkpresent.Checked)
{
gvrow.BackColor = ColorTranslator.FromHtml("#4caf50");
}
}
}
catch (Exception)
{
}
}
}
All-Star
50831 Points
9895 Posts
Re: Show values in gridview ,Datalist in asp.net
Dec 08, 2016 03:08 PM|A2H|LINK
Please provide more details on what is the actual error you are getting.
You have an empty catch block in your code. if you have like this then you wont be able to get any error details.
Implement try catch like this : https://msdn.microsoft.com/en-us/library/xtd0s8kd(v=vs.110).aspx
Aje
My Blog | Dotnet Funda
Member
18 Points
83 Posts
Re: Show values in gridview ,Datalist in asp.net
Dec 08, 2016 04:22 PM|satyam khare|LINK
a2h
Error is resolved but still having one problem that
When I bind the dt to gridview it's showing only the last selected radio button coulmn value
Because the previous values are not saving in datatable
Can you tell me how to add my values in dt
And after all values added to datatable then it assign to gridview
All-Star
50831 Points
9895 Posts
Re: Show values in gridview ,Datalist in asp.net
Dec 09, 2016 02:41 PM|A2H|LINK
You might consider saving the values to database when user selects a row and then populate the gridview from database.
Aje
My Blog | Dotnet Funda