ASP.NET Edit every record in Datalist - asp.net

I currently have a DataList control, with the ItemTemplate and EditItemTemplate defined.
<asp:DataList ID="UserMatrixDataList" runat="server" RepeatColumns = "1" CellSpacing = "6" RepeatLayout="Table" BorderWidth="5">
<ItemTemplate>
<table class="table">
<col width="130">
<col width="800">
<tr>
<td >
<strong>Level</strong>
</td>
<td>
<asp:Label ID="lblLevel" runat="server" Text='<%# Eval("Level")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table class="table">
col width="130">
<col width="800">
<tr>
<td >
<strong>Level</strong>
</td>
<td>
<asp:Textbox ID="txtLevel" runat="server" Text='<%# Eval("Level")%>'></asp:Textbox>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:DataList>
After I do a Databind(), may I ask how can I set all records in the datalist to EditMode?

Related

aspx repeater Do something with the data

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>

Get the index of the clicked hyperlink in list view

The data is displayed from database as follows using list view.I have a hyperlink in list View on click of which i need to set session with the id or datakey of the clicked item row.how can i get it?
<asp:ListView ID="lstvwResultInquiry" runat="server" DataKeyNames="inquiry_id"
onitemdatabound="ListView1_ItemDataBound"
onpagepropertieschanging="PagePropertiesChanging"
onitemcanceling="CancelListViewItem" onitemediting="EditListViewItem"
onselectedindexchanging="lstvwResultInquiry_SelectedIndexChanging" >
<LayoutTemplate >
<div id="rightnowIn">
<table class="gridview"cellpadding="5" cellspacing="5" >
<tr class="header">
<th width="140">Company</th>
<th width="220">Event</th>
<th width="125">Country</th>
<th width="125">Date</th>
<th width="100">Details</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
<tr id="Tr1" runat="server" align="center" >
<td colspan="2" align="left"><asp:Label ID="lblCount" runat="server"></asp:Label></td>
<td id="Td1" runat="server" style="" colspan="4">
<asp:DataPager class="mpart" ID="DataPager1" PageSize="15" runat="server" align="center">
<Fields>
<asp:NumericPagerField ButtonType="Link"ButtonCount="3" PreviousPageText="<<<" NextPageText=">>>" />
</Fields>
</asp:DataPager>
</td>
<td colspan="2" align="left"></td></tr></table>
</LayoutTemplate>
<ItemTemplate >
<tr class="itemTemplateTr" >
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" commandName="view" cssclass="linkEditButton" Font-Underline="True"/</td
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td> </tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="alternatingItem">
<td style="color: #403f3f; font-weight: bold;"><%# Eval("company")%></td>
<td><asp:Label ID="lblEvents" runat="server" ></asp:Label></td>
<td><%# Eval("country_name")%></td>
<td><%# Eval("date", "{0:dd-MM-yyyy}")%></td>
<% if (Session["session_log_id"] != null)
{ %>
<td class="command"><asp:HyperLink ID="btnEdit" runat="server" Text="View" cssclass="linkEditButton" Font-Underline="True" /></td>
<%} %>
<td>
<asp:Button ID="buttReminder" runat="server" Visible="false" CssClass="reminderButton" CommandArgument='<%# Eval("inquiry_id")%>' OnClick="buttReminderInquiry_Click" BorderStyle="None" /></td>
</tr></AlternatingItemTemplate>
<EmptyDataTemplate>
<div style="text-align:center;font-weight:bold">0 Results Founds</div>
</EmptyDataTemplate>
</asp:ListView>
Now I want to know the row index clicked on click of hyperlink.I want to set the session with the datakey on the selected row i.e clicked hyperlink.

add CSS to a table row when databinding an asp listview

I am populating a Listview control from my codebehind.
Does anyone know of a way i can assign a css style to a table cell, is say the lowest price is greater than the amazon price?
<asp:ListView ID="lv1" runat="server" ItemPlaceholderID="itemPlaceholder" OnPagePropertiesChanging="ChangePage">
<LayoutTemplate>
<table id="dataTable">
<thead>
<tr>
<th class="t-left">Product Title</th>
<th>SKU</th>
<th>Our Price</th>
<th>Amazon Price</th>
<th>Lowest Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="dataResults" >
<tr id="itemPlaceholder" runat="server"></tr>
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id='<%#Eval("sku") %>'>
<td class="t-left" width="360px">
<asp:HyperLink ID="prodLnk" runat="server" NavigateUrl='<%#"~/product/editproduct.aspx?sku=" + Eval("sku") %>' ToolTip="Edit this product listing">
<asp:Label runat="server" ID="lblTitle"><%#Eval("title") %></asp:Label>
</asp:HyperLink>
</td>
<td><asp:Label runat="server" ID="lblSku"><%#Eval("sku") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblTWE">£<%#Eval("twePrice") %></asp:Label></td>
<td class="amzprice-edit"><input type="text" id='<%#"txt" + Eval("sku") %>' value='<%#Eval("amzPrice") %>'> </td></td>
<td>
<asp:Label runat="server" ID="lblLow">£<%#Eval("lowprice")%></asp:Label>
<img src="images/icons/graph-icon.png" alt="Info" title="View Lowprice History" />
</td>
<td><div class="twe-button mini update">Update</div></td>
</tr>
</ItemTemplate>
</asp:ListView>
The simplest way to do this is to add an additional property to your object/data source and then use that in the databinding stage.
For example, create a boolean property called LowestPrice
You can then evaluate this when databinding:
class='<%# Eval("LowestPrice") == true ? "BuyMeNow" : "BuyMeLater" %>'
Your example above would become something like:
<ItemTemplate>
<tr id='<%#Eval("sku") %>' class='<%# Eval("LowestPrice") == true ? "BuyMeNow" : "BuyMeLater" %>'>
<td class="t-left" width="360px">
<asp:HyperLink ID="prodLnk" runat="server" NavigateUrl='<%#"~/product/editproduct.aspx?sku=" + Eval("sku") %>' ToolTip="Edit this product listing">
<asp:Label runat="server" ID="lblTitle"><%#Eval("title") %></asp:Label>
</asp:HyperLink>
</td>
<td><asp:Label runat="server" ID="lblSku"><%#Eval("sku") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblTWE">£<%#Eval("twePrice") %></asp:Label></td>
<td class="amzprice-edit"><input type="text" id='<%#"txt" + Eval("sku") %>' value='<%#Eval("amzPrice") %>'> </td></td>
<td>
<asp:Label runat="server" ID="lblLow">£<%#Eval("lowprice")%></asp:Label>
<img src="images/icons/graph-icon.png" alt="Info" title="View Lowprice History" />
</td>
<td><div class="twe-button mini update">Update</div></td>
</tr>
</ItemTemplate>
Which would apply the class BuyMeNow to the row when LowestPrice is true.

How to set radio button Id property based on database value?

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.

Toggle rows created using Repeater Control ASP.NET

I am creating a list of data using Repeater Control. Some of the rows might have other rows that should be toggled using the main row's clickable image.
Here, is the HTML part
<table cellpadding="2" cellspacing="0" width="100%">
<asp:Repeater ID="repeatLockers" runat="Server">
<HeaderTemplate>
<tr>
<td> </td>
<td>A</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="trItem" class="SomeParentClass" runat="server">
<td>
<img id="imgToggleHomeInfo" runat="server" alt="show/hide repetitves" src="icon_plus.gif"
style="cursor: pointer" />
</td>
<td>
<asp:Label ID="lbl" runat="server"></asp:Label>
</td>
</tr>
<tr id="trAddOnFee" runat="server" class="SomeClass" style="display: none;">
<td colspan="2">
<table cellpadding="4" cellspacing="2" width="100%">
<tr>
<td class="DgHeader">A</td>
<td class="DgHeader">B</td>
</tr>
<asp:Repeater ID="repeatRepetitives" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblA" runat="server"></asp:Label>
</td>
<td align="right">
<asp:Label ID="lblB" runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
How could I toggle the Rows with class as "SomeClass" inside on click of imgToggleHomeInfo" image on its parent row using Jquery?
I'd find the parent row of the image then toggle it's next sibling.
$(document).ready( function() {
$("[id$='imageToggleHomeInfo']").click( function() {
$(this).closest('tr').next().toggle();
});
})

Resources