I have grid view which contains five radio buttons per row. Out of these five only one can be checked at a time. To achieve this I tried to keep Id property of radio button corresponding to database value. But it gives me an error in Id field. .Net does not allow to use eval function in ID property. The rows will depend on number of records in database. I want to keep 5 radio button in database and out of these five, only one can be checked. How to achieve this task?
//My code of .aspx page is as below.
<%# Page Title="Applicant Rating Form" Language="C#" MasterPageFile="~/Interviewer/interviewerMasterPage.master" AutoEventWireup="true" CodeFile="AppRatingForm.aspx.cs" Inherits="Interviewer_AppRatingForm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table cellpadding="2" width="100%">
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td align="center" class="tdtitle" colspan="2">
Interview Rating Form</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td width="25%">
Name of Applicant</td>
<td>
<asp:Label ID="nameLbl" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
Post Applied For</td>
<td>
</td>
</tr>
<tr>
<td>
Department</td>
<td>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td align="center" class="tdtitle" colspan="2">
Assessment</td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:GridView ID="assesmentGrid" runat="server" AutoGenerateColumns="False"
onpageindexchanging="assesmentGrid_PageIndexChanging">
<Columns>
<asp:BoundField HeaderText="ID" DataField="SecId"/>
<asp:BoundField HeaderText="Traits" DataField="SecName"/>
<asp:TemplateField>
<HeaderTemplate>
A
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID='<%# Eval("SecId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
B
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID='<%# Eval("SecId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
C
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID='<%# Eval("SecId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
D
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID='<%# Eval("SecId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
E
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID='<%# Eval("SecId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Comments
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="commentBox" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td align="center" class="tdtitle" colspan="2">
</td>
</tr>
<tr>
<td align="center" colspan="2">
</td>
</tr>
<tr>
<td align="center" colspan="2">
</td>
</tr>
</table>
</asp:Content>
You need to set the GroupName property of all RadioButtons in the same group/row. This will only allow one to be selected at a time. I wouldn't suggest trying to set the IDs dynamically using Eval, just make sure they are all unique and it should work fine.
Related
I have made a webform, and by using a repeater i would like to display the results with the option of approving/disapproving applicants. I have searched high and low, but I am unable to discover how i can use the data of the item in the item repeater. If someone could point me in the right direction as to how i could do this i would appreciate it alot.
So as example. Someone presses the button approve in one of the repeated items. and i would like to do some db query using the email address which is displayed in that item
codebehind:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if(((Button)e.CommandSource).Text.Equals("Approve"))
{
//
}
}
and this is the aspx:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<div class="Application">
<table class="auto-style1">
<tr>
<td class="small">Application received:</td>
<td class="big"><asp:Label ID="lbl_App_Date" runat="server" Text='<%# Eval("app_date") %>'></asp:Label></td>
<td class="small">Status:</td>
<td class="small"><asp:Label ID="lbl_App_status" runat="server" Text='<%# Eval("app_status") %>'></asp:Label></td>
</tr>
<tr>
<td class="small">Email Address: </td>
<td class="big"><asp:Label ID="lbl_App_email" runat="server" Text='<%# Eval("app_email") %>'></asp:Label></td>
<td class="small">Age: </td>
<td class="small"><asp:Label ID="lbl_App_age" runat="server" Text='<%# Eval("app_age") %>'></asp:Label></td>
</tr>
<tr>
<td>Country: </td>
<td><asp:Label ID="lbl_App_Country" runat="server" Text='<%# Eval("app_country") %>'></asp:Label></td>
<td>Platform: </td>
<td><asp:Label ID="lbl_App_Platform" runat="server" Text='<%# Eval("app_platform") %>'></asp:Label></td>
</tr>
</table>
<p><b>Motivation to join: </b></p>
<asp:TextBox ID="txt_App_Moti" ReadOnly="true" Text='<%# Eval("app_moti") %>' TextMode="MultiLine" Height="150px" Width="60%" runat="server"></asp:TextBox>
<asp:Panel ID="pan_approval" runat="server">
<table class="auto-style1">
<tr>
<td class="small"></td>
<td class="big"><asp:Button ID="btn_approve" runat="server" Text="Approve" /></td>
<td class="small"></td>
<td class="small"><asp:Button ID="btn_disapprove" runat="server" Text="Disapprove" /></td>
</tr>
</table>
</asp:Panel>
</div>
</ItemTemplate>
</asp:Repeater>
This is part of my code that isn't working. I have looked for somethings, but i cannot search what my asp:ListView isn't showing, if someone knows about it, Help me !
<asp:ListView ItemPlaceholderID="PlaceHolder1" runat="server" ID="ListViewUser">
<LayoutTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"/>
<table id="Table1" class="TableListView" runat="server">
<tr id="Tr1" class="TableHeader" runat="server">
<td id="td1" runat="server">Nível</td>
<td id="td2" runat="server">Descrição</td>
<td id="td3" runat="server">Quantidade de Problema ?</td>
<td id="td4" runat="server">Selecionar</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="ItemsCSS">
<td>
<asp:Label runat="server"
ID="Label1"
Text="Problema" >
</asp:Label>
</td>
<td>
<asp:Label runat="server"
ID="Label2"
Text="Problema" >
</asp:Label>
</td>
<td>
<asp:Label runat="server"
ID="Label3"
Text="Problema" >
</asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Your ListView lacks bindings. You can add a DataSourceID property to the top level control and point to a DataSource control or programmatically bind to the DataSource property and then invoke DataBind(). But the control will not display anything without first binding it.
I have an ASP.NET repeater with an ImageButton. My ImageButton has an OnCommand event.
My goal: When I click the ImageButton, I would like the color of the selected row to change.
Here is an excerpt from my ASP.NET code. Can anyone help me?
<asp:Repeater ID="RepeaterID" runat="server" OnItemCommand="rpt_ItemCommand">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" id="table1">
<thead>
<tr>
<th>
<asp:Label ID="lbl_refCode" runat="server"></asp:Label>
</th>
<th style="width: 25px"></th>
</tr>
</thead>
</table>
</HeaderTemplate>
<ItemTemplate>
<tr id="row" runat="server">
<td style="width: 50px;">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("RefCode") %>'</asp:Label>
</td>
<td style="width: 25px;">
<asp:ImageButton ImageUrl="Icons/edit.png" CommandArgument='<%# Eval("ID") %>' CommandName="Edit" ID="ImgEdit" OnCommand="Manage" runat="server">
</asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="row" runat="server">
<td style="width: 50px;">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("RefCode") %>' </asp:Label>
</td>
<td style="width: 25px;">
<asp:ImageButton ImageUrl="Icons/edit.png" CommandArgument='<%# Eval("ID") %>' CommandName="Edit" ID="ImgEdit" OnCommand="Manage" runat="server">
</asp:ImageButton>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</asp:Repeater>
Try using the OnItemCommand event of the Repeater instead of the LinkButton's OnCommand event. The RepeaterCommandEventArgs parameter will give you access to the whole Item instead of just the LinkButton, and you can set the background color of the table row.
<asp:Repeater ID="RepeaterID" runat="server" OnItemCommand="rpt_ItemCommand">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" id="table1">
<thead>
<tr>
<th>
<asp:Label ID="lbl_refCode" runat="server" </asp:Label>
</th>
<th style="width: 25px"></th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr id="row" runat="server">
<td style="width: 50px;">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("RefCode") %>' </asp:Label>
</td>
<td style="width: 25px;">
<asp:ImageButton ImageUrl="Icons/edit.png" CommandArgument='<%# Eval("ID") %>' CommandName="Edit" ID="ImgEdit" runat="server">
</asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="row" runat="server">
<td style="width: 50px;">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("RefCode") %>' </asp:Label>
</td>
<td style="width: 25px;">
<asp:ImageButton ImageUrl="Icons/edit.png" CommandArgument='<%# Eval("ID") %>' CommandName="Edit" ID="ImgEdit" runat="server">
</asp:ImageButton>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</asp:Repeater>
protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Edit"))
{
HtmlTableRow newRow = e.Item.FindControl("row") as HtmlTableRow;
if (newRow != null)
newRow.BgColor = "#CCCCCC";
}
}
Note that in the ItemTemplate the table row has an id so it can be found in the ItemCommand argument.
i have this listview with news...
But each new news is in the new row...
I need 3 news in each row...
<asp:ListView ID="ListView2" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="NovinkaLabel" runat="server" Text='<%# Eval("Novinka") %>' />
</td>
</tr>
</table>
</AlternatingItemTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="NovinkaLabel" runat="server" Text='<%# Eval("Novinka") %>' />
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr>
<td>
</td>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
This listview write each new into next row...but i need THREE news into ONE ROW.
It is possible?
Try likes this !
<asp:ListView ID="ListView2" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<table>
<td>
<asp:Label ID="NovinkaLabel" runat="server" Text='<%# Eval("Novinka") %>' />
</td>
</table>
</AlternatingItemTemplate>
<ItemTemplate>
<table>
<td>
<asp:Label ID="NovinkaLabel" runat="server" Text='<%# Eval("Novinka") %>' />
</td>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
or
Change your listView to datalist , reference HERE . It's what you need !
In a simple way ,
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="NovinkaLabel" runat="server" Text='<%# Eval("Novinka") %>' />
</ItemTemplate>
</asp:DataList>
On chkSubModuleView_CheckedChanged() event iwant to get the id of chkModule.Please tell me how to get the id or reference of parent checkbox on click of child checkbox in server side.How to distinguish between different modules .
enter code here
<asp:ListView ID="lvModule" runat="server">
<LayoutTemplate>
<table width="600px" border="0" cellpadding="0" cellspacing="0"
class="ListViewtable">
<tr>
<th style="width: 10%;">
Modules
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server">
</asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkModule" runat="server"
CausesValidation="false" AutoPostBack="true"
OnCheckedChanged="chkModule_CheckedChanged" >
</asp:CheckBox><asp:HiddenField ID="hfEntityName"
Value='<%# Eval("EntityName") %>' runat="server" />
<%# Eval("Title")%>
<asp:HiddenField ID="hfID" Value='<%# Eval("ID") %>'
runat="server" />
<asp:Label ID="label" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 20px;">
<asp:ListView ID="lvSubModule" runat="server">
<LayoutTemplate>
<table width="100%" cellspacing="0" border="0"
class="ListViewtableLayer2">
<tr>
<th style="width: 20%;">
Sub Module
</th>
<th style="width: 20%;">
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true"
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
View
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder"
runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("Title")%>
<asp:HiddenField ID="hfMenuID" Value='<%#
Eval("MenuID") %>' runat="server" />
<asp:HiddenField ID="hfName" Value='<%#
Eval("HeaderID") %>' runat="server" />
</td>
<td>
<asp:CheckBox ID="chkRead" runat="server"
AutoPostBack="true" Checked="true" CausesValidation="false"
OnCheckedChanged="chkRead_CheckedChanged"></asp:CheckBox>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
change your checkbox property to
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true" Key='<%# Eval("ID")%>'
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
In your .cs
protected void chkSubModuleView_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
string yourID = chk.Attributes["Key"].ToString();
}