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>
Related
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>
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
 
</asp:TableRow>
</asp:Table>
<table>
<tr>
<td>
 
</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
The code below get me a comment , puts it in the database and then waits for a page reload to show the comment. How can i make the submited comment to be shown right after it has been posted along with the new ones ? This is the code that does the stuff :
Layout:
<table>
<tr>
<td colspan="2">All Comments</td>
<td>
 
</td>
</tr>
<tr> <td colspan="2"> </td></tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments" >
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</td>
</tr>
<td>
<table>
<tr>
<td colspan="2" >Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>
 
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>
 
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>
 
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
Code Behind:
public void fnSubmitComment()
{
AddComment cmt = new AddComment();
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
bool addSucces = cmt.Addcomment( y , txtcomment.Text);
if (addSucces)
{
lblStatus.Text = "Your Comment has been Added Successfully.";
}
else
{
lblStatus.Text = "Your Comment has not been Added.";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
fnSubmitComment();
}
public IQueryable<Comments> GetComments()
{
var _db = new SiteStiri.Models.CommentsContext();
IQueryable<Comments> query = _db.Comments;
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
query = query.Where(p => p.NewsID == y);
return query;
}
I heard i can do that with ajax ? (My knowledge about ajax is 0 currently) Any tips on how i can do this ?
You must wrapper you repeater in an updatepanel,
set UpdateMode="Conditional" and add a trigger on btnSubmit so when click the button the update the repeater with the normal page life cycle
Remember to bind the repeater after that you add the commet in the codebehind and must be present in your page a ScriptManager control
more or less thus
<asp:ScriptManager runat="server" />
<table>
<tr>
<td colspan="2">All Comments</td>
<td> 
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td colspan="2">Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td> 
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td> 
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td> 
</td>
</tr>
</table>
</td>
</tr>
</table>
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;
I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.