Asp.net Choose one from generated radio button - c#

I have the code below, the group name didn't work,
the user can choose any more than one from radio button
<asp:ListView ID="lstActive" runat="server" OnItemDataBound="lstAllWActive_ItemDataBound">
<ItemTemplate>
<tr>
<td><%# Eval("PollQuestion") %></td>
<td>
<asp:HiddenField ID="hdPollId" runat="server" Value='<%#Eval("PollId")%>' />
<asp:ListView ID="lstOptionWPrecentage" runat="server">
<ItemTemplate>
<div class='col-md-4'>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("Id")%>' />
<asp:RadioButton ID="po1" runat="server" GroupName="jhhhh" ValidationGroup="poll" />
<label for='po1'><%# Eval("OptionText") %> </label>
</div>
</ItemTemplate>
</asp:ListView>
</td>
<td><%# Eval("PollName") %> </td>
</tr>
</ItemTemplate>
</asp:ListView>

thanks for helping me it's done ok as they say above
<asp:ListView ID="lstActive" runat="server" OnItemDataBound="lstActive_ItemDataBound" >
<ItemTemplate>
<tr>
<td><%# Eval("PollQuestion") %></td>
<td> <asp:HiddenField ID="hdPollId" runat="server"
Value='<%#Eval("PollId")%>' />
<div class='col-md-4'> <asp:RadioButtonList ID="RadioButtonList1"
runat="server" DataTextField="OptionText" DataValueField="Id">
</asp:RadioButtonList>
</div> </td>
<td><%# Eval("PollName") %> </td>
</tr>
</ItemTemplate>
</asp:ListView>

Related

How to bind nested repeater using imagebutton in updatepanel

I was using a simple html img with jQuery to show the nested table and binding the repeater on itemdatabound. Problem is, this was very expensive by getting all sub items from items in the list at the same time. So I decided it's better when i click the collapse image to show the nested table I should bind the repeater in there.
For this I use imagebutton and command argument to get the ID and use update panel to stop postback from button, but the repeater won't update?
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="rptInventarioLocalizacoes_ItemCommand">
<HeaderTemplate>
<table id="tblInventarioLocalizacoes" class="table table-bordered table-striped dataTable text-center">
<thead class="thead-dark">
<tr>
<th></th>
<th>Nª</th>
<th>Localização</th>
<th>Etq. Por Inventariar</th>
<th>Etq. Inventariadas</th>
<th>Precisão</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:ImageButton ID="ibtnCollapse" runat="server" Style="cursor: pointer" ImageUrl="../../Images/Collapse/plus.png" Width="20" CommandName="BindEtiquetas" CommandArgument='<%# Eval("Localizacao") %>' />
<asp:Panel ID="pnlInventarioEtiquetas" runat="server" Style="display: none">
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ibtnCollapse" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptLocalizacoesEtiquetas" runat="server">
<HeaderTemplate>
<table id="tblLocalizacoesEtiquetas" class="nestedtable table table-bordered table-striped dataTable">
<thead class="thead-dark">
<tr>
<th>#</th>
<th>Etiqueta</th>
<th>Validar</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
</td>
<td>
<asp:Label ID="lblEtiqueta" runat="server" Text='<%# Eval("Etiqueta") %>' />
</td>
<td>
<asp:CheckBox ID="chkEtiqueta" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
<asp:Button ID="btnAddEtiqueta" runat="server" CssClass="btn btn-default" Text="Adicionar Etiqueta" BackColor="#020023" ForeColor="White" Font-Bold="true" />
<asp:Button ID="btnInventariar" runat="server" CssClass="btn btn-default" Text="Inventariar Etiquetas" BackColor="#020023" ForeColor="White" Font-Bold="true" />
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</td>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
<asp:Label ID="lblIdlocalizacao" runat="server" Text='<%# Eval("IdInventarioLocalizacao") %>' Style="display: none" />
</td>
<td>
<asp:Label ID="lblLocalizacao" runat="server" Text='<%# Eval("Localizacao") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasPorInventariar" runat="server" Text='<%# Eval("EtiquetasPorInventariar") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasInventariadas" runat="server" Text='<%# Eval("EtiquetasInventariadas") %>' />
</td>
<td>
<asp:Label ID="lblPrecisao" runat="server" Text='<%# Eval("Precisao") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

unable to export html table content to excel in asp.net

when the html table is exported to excel from asp.net the table is displayed but the content inside the table is not displayed below is my code.
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
lblCategorystatusReportHeader.Visible = true;
Response.AddHeader("content-disposition",
"attachment;filename=StatusReport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//Panel preOrderPanel = (Panel)rpt1.FindControl("pnlPreOrder");
//rptCP.RenderControl(hw);
//pnlPreOrder.RenderControl(hw);
order.RenderControl(hw);
string output = sw.ToString();
output = "<html><head><meta charset=" + Encoding.UTF8.WebName + " /></head><body>" + output + "</body></html>";
Response.Output.Write(output);
Response.Flush();
Response.End();
lblCategorystatusReportHeader.Visible = false;
}
below is the aspx code
&nbsp
</asp:TableRow>
</asp:Table>
<table>
<tr>
<td>
&nbsp
</td>
</tr>
</table>
<table>
<%-- <tr style="text-align:center">
<td colspan="20" style="font-size:16px; padding-left:100px;background-color:#90cad9;border:1px solid black;display:none">
<b><asp:Label ID="lblCategorystatusReportHeader" runat="server" Text="Category Status Report"></asp:Label></b>
</td>
</tr>--%>
<tr>
<td style="width:150px !important;vertical-align:middle;text-align:center; border-style:solid; border-width:1px" rowspan="2">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>
<td>
<%-- <asp:Panel ID="pnlPreOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse">
<tr>
<%--<td stylwe="width:40px">
<asp:Label ID="lblCPPre" runat="server"></asp:Label>
</td>--%>
<td style="vertical-align:middle;background-color:#90cad9;text-align:center">
<div style="width:100px !important">Category CP</div>
</td>
<td>
<asp:Label ID="lblMessagePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePO" runat="server" OnItemDataBound="rptStylePO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse;border-spacing:0px">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"> <asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePre" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptt" runat="server" OnItemDataBound="rptt_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="width:60px;vertical-align:middle;text-align:center">
<div style="width:60px !important"><asp:HiddenField ID="stlId" runat="server" Value='<%# Container.DataItem.ToString() %>' /></div>
</td>
<td>
<asp:DataList ID="dataListPO" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPO_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse; border-spacing:0px" >
<tr>
<td style="word-wrap:break-word;width:110px; height:60px; color:#000000;vertical-align:middle;text-align:center; background-color:#90cad9 ; font-size:11px;">
<div style="word-wrap:break-word;width:100%;font-size:13px">
<asp:Label ID="lblMilestoneValue" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left;">
<asp:Table ID="tblStatus" runat="server" Width="100%">
<asp:TableRow ID="rowStatus" runat="server">
<asp:TableCell ID="cellStatus1" Width="25px" runat="server"><div style="width:100px; text-align:justify"><asp:Label ID="lblForecastedDate" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatus" Width="25px" runat="server"> <div style="width:100px; text-align:center">
<asp:Label ID="lblStatus" Font-Size="13px" runat="server" ForeColor="White"></asp:Label></div>
</asp:TableCell>
</asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDate" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDate" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDate" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatus" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
<tr>
<td>
<%-- <asp:Panel ID="pnlPostOrder" runat="server">--%>
<table border="1" style="border-collapse:collapse;">
<tr>
<%--<td style="width:40px">
<asp:Label ID="lblCPPost" runat="server"></asp:Label>
</td>--%>
<td style=" background-color:#90cad9; font-size:14px;vertical-align:middle;text-align:center;white-space:nowrap; " ><div style="width: 100px;">Item CP</div></td>
<td style="font-size:14px">
<asp:Label ID="lblMessagePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptStylePostOrder" runat="server" OnItemDataBound="rptStylePostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td class="stylestatusReport">
<div style="width:100px !important"><asp:HiddenField ID="styleid" runat="server" Value='<%# Container.DataItem.ToString() %>'/>
<asp:Label ID="lblStyle" runat="server"></asp:Label></div>
</td>
<td>
<asp:Label ID="lblNoMilestonePost" runat="server" Text="No Records found" Visible ="false" ForeColor="Red"></asp:Label>
<asp:Repeater ID="rptPO" runat="server" OnItemDataBound="rptPO_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td style="word-wrap:break-word;width:60px;vertical-align:middle;text-align:center;">
<div style="width:60px">
<asp:Label ID="lblPostOrderNumber" runat="server"></asp:Label>
<asp:HiddenField ID="hdnStylePOID" runat="server" Value='<%# Container.DataItem.ToString() %>'/></div>
</td>
<td>
<asp:DataList ID="dataListPostOrder" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dataListPostOrder_ItemDataBound">
<ItemTemplate>
<table border="1" style="border-collapse:collapse">
<tr>
<td style="word-wrap:break-word;width:110px; height:60px;background-color:#90cad9 ; font-size:11px;vertical-align:middle;text-align:center">
<div style="word-wrap:break-word;width:100%; font-size:13px"><asp:Label ID="lblMilestoneValuePost" runat="server" Text='<%# Eval("MilestoneName") %>'></asp:Label></div>
</td>
</tr>
<tr>
<td style="text-align:left">
<asp:Table ID="tblStatusPost" runat="server" Width="100%">
<asp:TableRow ID="rowStatusPost" runat="server">
<asp:TableCell ID="cellStatus1Post" Width="25px" runat="server">
<div style="width:100px;text-align:justify;"><asp:Label ID="lblForecastedDatePost" Font-Size="13px" runat="server" Width="50%" ForeColor="Black"></asp:Label></div></asp:TableCell>
<asp:TableCell ID="cellStatusPost" runat="server"><div style="width:100px;text-align:center">
<asp:Label ID="lblStatusPost" Font-Size="13px" runat="server" Width="100%" ForeColor="White"></asp:Label></div></asp:TableCell></asp:TableRow></asp:Table>
<asp:HiddenField ID="hdnPlannedDatePost" runat="server" Value='<%# Eval("MilestonePlannedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnRevisedDatePost" runat="server" Value='<%# Eval("MilestoneRevisedDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnActualDatePost" runat="server" Value='<%# Eval("MilestoneActualDate") %>'></asp:HiddenField>
<asp:HiddenField ID="hdnMilestoneStatusPost" runat="server" Value='<%# Eval("MilestoneStatus") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<%-- </asp:Panel>--%>
</td>
</tr>
</table>
[Below is the image of the table that is being displayed in excel.]
http://i.stack.imgur.com/JhHQo.png
actual image
[1]: http://i.stack.imgur.com/ghl8I.png

Creating a table column by column with repeater

I'm trying to make a comparison table for a website. There is a repeater which has a list of objects as the datasource.
The table will need to look like so:
Product1 Product2 Product3
ProductName1 ProductName2 ProductName3
ProductImage1 ProductImage2 ProductImage3
The problem is that I have the <tr> and <td> tags in the repeater and this causes the ProductNames to not be in the same row, so I get this:
Product1
ProductName1
ProductImage1
Product2
ProductName2
ProductImage2
Product3
ProductName3
ProductImage3
Is there a way to fill in the table column by column with the different items being in the same row?
Edit (added code):
<asp:PlaceHolder runat="server" ID="phPopUp">
<div id="popup-wrapper">
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<HeaderTemplate>
<table class="table-wrapper">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
</td>
</tr>
<tr>
<td class="product-image">
<img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
</td>
</tr>
<tr>
<td>
<%-- Features --%>
<asp:Literal runat="server" ID="ltFeatures" />
</td>
</tr>
<%-- <tr>
<td>
<asp:Literal ID="ltApplication" runat="server" />
</td>
</tr>--%>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
</td>
</tr>
<tr>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</tr>
<tr>
<td>
<asp:Literal ID="colors" runat="server" />
<asp:BulletedList runat="server" ID="blColors" />
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</tr>
<tr>
<td>
<asp:Literal runat="server" ID="ltVolumes" />
</td>
</tr>
<tr>
<td>
<%-- substrate --%>
</td>
</tr>
<tr>
<td>
<%-- finish --%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
repeat the repeater in each row:
<asp:PlaceHolder runat="server" ID="phPopUp">
<div id="popup-wrapper">
<table class="table-wrapper">
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td class="product-image">
<img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- Features --%>
<asp:Literal runat="server" ID="ltFeatures" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<%-- <tr>
<td>
<asp:Literal ID="ltApplication" runat="server" />
</td>
</tr>--%>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<asp:Literal ID="colors" runat="server" />
<asp:BulletedList runat="server" ID="blColors" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<asp:Literal runat="server" ID="ltVolumes" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- substrate --%>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- finish --%>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>

How to retrieve TD value of table column (ID) which is inside a repeater

I have a repeater with a HTML Table layout as follows where it fills from the database dynamically,
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th colspan="2"></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "QuestionId") %> <asp:HiddenField ID="hiddenField" Value='<%# DataBinder.Eval(Container.DataItem, "QuestionId") %>' runat="server" /> </td>
<td>
<table>
<tr>
<td colspan="4"><%# DataBinder.Eval(Container.DataItem, "Question") %> </td>
</tr>
<tr><td><asp:RadioButton ID="op1" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer1") %> </td></tr>
<tr><td><asp:RadioButton ID="op2" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer2") %> </td></tr>
<tr><td><asp:RadioButton ID="op3" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer3") %> </td></tr>
<tr><td><asp:RadioButton ID="op4" runat="server" OnCheckedChange="check_Answer"/></td><td><%# DataBinder.Eval(Container.DataItem, "Answer4") %> </td></tr>
</table>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
In Code Behind
protected void check_Answer(object sender, EventArgs e)
{
RepeaterItem item = (sender as RadioButton).Parent as RepeaterItem;
HiddenField hiddenField = item.FindControl("hiddenField") as HiddenField;
String questionId = hiddenField.Value;
Session["test"] = questionId;/*Just added to a session and passed to test page*/
Response.Redirect("test.aspx");/*This Page Displays the value of Session["test"]*/
}
Now what I need to do is OnCheckedChange event for the radio buttons it calls a code behind method, but should pass the QuestionID value to the method. Please suggest me a way to retrieve the value which contains the "QuestionID". For More Information the real interface looks like below,
You can group option buttons and use questionid as a part of group name. In the code you can get the questionid from GroupName. So you don't really need any hidden field. Your markup may look like below:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th colspan="2"></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "QuestionId") %> </td>
<td>
<table>
<tr>
<td colspan="4"><%# DataBinder.Eval(Container.DataItem, "Question") %> </td>
</tr>
<tr>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer1") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer2") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer3") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
<td><asp:RadioButton ID="RadioButton4" runat="server" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "Answer4") %>'
OnCheckedChanged="check_Answer" GroupName='<%# Eval("QuestionId","Grp_{0}") %>' />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
And in the code:
protected void check_Answer(object sender, EventArgs e)
{
string grpId = ((RadioButton)sender).GroupName;
string questionId = grpId.Split('_')[1].ToString();
Session["test"] = questionId;/*Just added to a session and passed to test page*/
Response.Redirect("test.aspx");/*This Page Displays the value of Session["test"]*/
}
I would add hidden field as below
<asp:HiddenField ID="hiddenField" Value='<%# DataBinder.Eval(Container.DataItem, "QuestionId") %>' runat="server" />
in your check_Answer event
RepeaterItem item = (sender as RadioButton).Parent as RepeaterItem;
HiddenField hiddenField = item.FindControl("hiddenField") as HiddenField;
string questionId= hiddenField.Value;

how to assign an item template (eval) value to a label outside the asp.net gridview control

I would like to assign the
<%# DataBinder.Eval(Container.DataItem, "Name")%>
which is within the gridview to a a label
Label2
outside the gridview. I cant figure out a way to do it since the Eval value is within the Gridview and I
need to use it outside the gridview. I have the code below.
Please let me know.
<div class="ModalPopup" id="PopupDiv1">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<div class="modalHeader">
<table width="100%">
<tr>
<td class="title">
<asp:Label ID="Label2" Font-Bold="true" runat="server"></asp:Label>
</td>
<td>
<a href="javascript:void(0);" onclick="javascript:CloseModelPopup1();" class="CloseModal">
X</a>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div id="Div1" class="InsertBar">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="left" ScrollBars="Auto">
<asp:GridView ID="gDetails" OnRowDataBound="gvDetails_RowDataBound"
Orunat="server" CellPadding="5"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image Width="32px" ID="statusImage" runat="server" Height="32px"></asp:Image>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LogId">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "LogId") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name")%> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Try this out
<div class="ModalPopup" id="PopupDiv1">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<div class="modalHeader">
<table width="100%">
<tr>
<td class="title">
<asp:Label ID="Label2" Font-Bold="true" runat="server"></asp:Label>
</td>
<td>
<a href="javascript:void(0);" onclick="javascript:CloseModelPopup1();" class="CloseModal">
X</a>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div id="Div1" class="InsertBar">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="left" ScrollBars="Auto">
<asp:GridView ID="gDetails" OnRowDataBound="gvDetails_RowDataBound"
Orunat="server" CellPadding="5"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image Width="32px" ID="statusImage" runat="server" Height="32px"></asp:Image>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LogId">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "LogId") %>
CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="btnRequest"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Name")%> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>

Categories