I have the following: repeater with a couple rows. each row starts with linkbutton with which can i navigate to another page. what I now want to do is that I can click the whole row with the same clicking functionality of the linkbutton.
Here is my Repeater:
<table>
<tr>
<td>
<asp:Repeater ID="rptTasks" runat="server" onitemcommand="rptTasks_ItemCommand"
onitemdatabound="rptTasks_ItemDataBound" onitemcreated="rptTasks_ItemCreated">
<HeaderTemplate>
<table>
<tr>
<td colspan="8"></td>
<td colspan="2"> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server" CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server" CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>
</tr>
</table>
</AlternatingItemTemplate>
<FooterTemplate>
<tr>
<td colspan="5" align="left">
<asp:Label ID="lblCurrentPage"
runat="server"></asp:Label>
</td>
<td colspan="5" align="right">
<asp:HyperLink ID="lnkPrev" runat="server" Text="<< Prev"></asp:HyperLink>
<asp:HyperLink ID="lnkNext" runat="server" Text="Next>>"></asp:HyperLink>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
I have also used javascript to get the selected row:
<script type="text/javascript" >
function Select(obj)
{
obj.className = 'selected';
var tbl = document.getElementById("table1")
var firstRow = tbl.getElementsByTagName("TR")[0];
var oldRow = tbl.rows[firstRow.getElementsByTagName("input")[0].value];
if (oldRow != null)
{
oldRow.className = '';
}
firstRow.getElementsByTagName("input")[0].value = obj.rowIndex;
}
</script>
<script type="text/C#" >
onclick="this.getElementsByTagName('input')[0].clicked=true;
</script>
When i give the second table tag an id="table1" i get jscript error, oldRow unknown
Does someone know a solution for this issue? for clarity: I want clicking on an row and then navigating just like if I click on the first linkbutton of each row.
In advance thanks.
$(function () {
SetNaigationToSearchList();
}
);
function SetNaigationToSearchList() {
$("tr td")
.css("cursor", "pointer")//set the pointer cursor for table row
.click(function () {
$row = $(this).parent();
var ID = $("td", $row).eq(0).text();//Get the 0 th col value of the cliked index...
alert('clicked');
}
});
}
Related
Error Message: the name 'DriverObjNameDD' does not exist in current context (Lines in cdoe behind where 'DriverObjNameDD' is referenced)
It appears that the code behind methods are in the same namespace as the .aspx file where the InsertItemTemplate would be. I believe the placeholder would also be a part of linking the InsertItemTemplate so that there would be access, but that does not seem to be the case.
Code behind
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EstimationToolForms.EstimationAdmin
{
public partial class CreateTypeTemplateObject : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["DefaultEstimateConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM et_TypeObject"))
{
cmd.Parameters.Clear();
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataTable TypeObjdt = new DataTable();
SqlDataAdapter TypeObjda = new SqlDataAdapter(cmd);
TypeObjda.Fill(TypeObjdt);
TypeTemplateLV.DataSource = TypeObjdt;
TypeTemplateLV.DataBind();
}
}
}
protected void DriverObjName_TextChanged(object sender, EventArgs e)
{
//ListViewItem item = TypeTemplateLV.Items[];
//DropDownList DriverDescriptionDD = (DropDownList)item.FindControl("DriverObjName");
//DropDownList DriverDescriptionDD = (DropDownList)TypeTemplateLV.FindControl("DriverObjName"); //
//int Driverid = Int32.Parse(DriverDescriptionDD.DataValueField); //
string constr = ConfigurationManager.ConnectionStrings["DefaultEstimateConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM et_DriverObject"))
{
cmd.Parameters.Clear();
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataTable DrvrObjdt = new DataTable();
SqlDataAdapter DrvrObjda = new SqlDataAdapter(cmd);
DrvrObjda.Fill(DrvrObjdt);
DriverObjNameDD.DataSource = DrvrObjdt;
DriverObjNameDD.DataBind();
DriverObjNameDD.DataTextField = "Name";
DriverObjNameDD.DataValueField = "ID";
DriverObjNameDD.DataBind();
DropDownList DriverDropDown = (DropDownList) TypeTemplateLV.FindControl("DriverObjName");
DriverObjName.DataSource = DrvrObjdt;
TypeTemplateLV.DataBind();
}
}
Aspx file
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="CreateTypeTemplateObject.aspx.cs" Inherits="EstimationToolForms.EstimationAdmin.CreateTypeTemplateObject" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:ListView ID="TypeTemplateLV" runat="server" DataKeyNames="ID" InsertItemPosition="LastItem" ItemPlaceholderID="itemPlaceholder" GroupPlaceholderID="groupplaceholder">
<GroupTemplate>
<tr>
<asp:TreeView ID="itemplaceholder" runat="server"></asp:TreeView>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<tr>
<td>
<asp:Label ID="Namelbl" runat="server" Text="Task Name: "></asp:Label>
<asp:TextBox ID="TypeNameTextBox" runat="server" Text='<%# Bind("TypeName") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="DriverDropDownlbl" runat="server" Text="Driver Name: "></asp:Label>
<asp:DropDownList runat="server" ID="DriverObjNameDD" DataTextField= ></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Indicatorlbl" runat="server" Text="Check if LOE: "></asp:Label>
<asp:CheckBox ID="LOEIndicatorCheckBox" runat="server" Checked='<%# Bind("LOEIndicator") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Orderlbl" runat="server" Text="Order of math operation: "></asp:Label>
<asp:TextBox ID="OrderTextBox" runat="server" Text='<%# Bind("Order") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="BaseVallbl" runat="server" Text="Base Value: "></asp:Label>
<asp:TextBox ID="BaseValueTextBox" runat="server" Text='<%# Bind("BaseValue") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="MathOperator" runat="server" Text="Math Operation: "></asp:Label>
<asp:DropDownList ID="MathOperatorDropDown" runat="server" >
<asp:ListItem Value="*">*</asp:ListItem>
<asp:ListItem Value="+">+</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription1lbl" runat="server" Text='<%# Eval("Opt1Description") %>'></asp:Label>
<asp:TextBox ID="Opt1ValueTextBox" runat="server" Text='<%# Bind("Opt1Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription2lbl" runat="server" Text='<%# Eval("Opt2Description") %>'></asp:Label>
<asp:TextBox ID="Opt2ValueTextBox" runat="server" Text='<%# Bind("Opt2Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription3lbl" runat="server" Text='<%# Eval("Opt3Description") %>'></asp:Label>
<asp:TextBox ID="Opt3ValueTextBox" runat="server" Text='<%# Bind("Opt3Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription4lbl" runat="server" Text='<%# Eval("Opt4Description") %>'></asp:Label>
<asp:TextBox ID="Opt4ValueTextBox" runat="server" Text='<%# Bind("Opt4Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription5lbl" runat="server" Text='<%# Eval("Opt5Description") %>'></asp:Label>
<asp:TextBox ID="Opt5ValueTextBox" runat="server" Text='<%# Bind("Opt5Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="OptDescription6lbl" runat="server" Text='<%# Eval("Opt6Description") %>'></asp:Label>
<asp:TextBox ID="Opt6ValueTextBox" runat="server" Text='<%# Bind("Opt6Value") %>' />
</td>
</tr>
<tr>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="TypeNameLabel" runat="server" Text='<%# Eval("TypeName") %>' />
</td>
<td>
<asp:Label ID="TypeDriverObjIDLabel" runat="server" Text='<%# Eval("TypeDriverObjID") %>' />
</td>
<!--td>
<asp:CheckBox ID="LOEIndicatorCheckBox" runat="server" Enabled="false" />
</td-->
<td>
<asp:Label ID="OrderLabel" runat="server" Text='<%# Eval("Order") %>' />
</td>
<td>
<asp:Label ID="BaseValueLabel" runat="server" Text='<%# Eval("BaseValue") %>' />
</td>
<td>
<asp:Label ID="MathOperatorLabel" runat="server" Text='<%# Eval("MathOperator") %>' />
</td>
<td>
<asp:Label ID="Opt1ValueLabel" runat="server" Text='<%# Eval("Opt1Value") %>' />
</td>
<td>
<asp:Label ID="Opt2ValueLabel" runat="server" Text='<%# Eval("Opt2Value") %>' />
</td>
<td>
<asp:Label ID="Opt3ValueLabel" runat="server" Text='<%# Eval("Opt3Value") %>' />
</td>
<td>
<asp:Label ID="Opt4ValueLabel" runat="server" Text='<%# Eval("Opt4Value") %>' />
</td>
<td>
<asp:Label ID="Opt5ValueLabel" runat="server" Text='<%# Eval("Opt5Value") %>' />
</td>
<td>
<asp:Label ID="Opt6ValueLabel" runat="server" Text='<%# Eval("Opt6Value") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">ID</th>
<th runat="server">TypeName</th>
<th runat="server">TypeDriverObjID</th>
<th runat="server">LOEIndicator</th>
<th runat="server">Order</th>
<th runat="server">BaseValue</th>
<th runat="server">MathOperator</th>
<th runat="server">Opt1Value</th>
<th runat="server">Opt2Value</th>
<th runat="server">Opt3Value</th>
<th runat="server">Opt4Value</th>
<th runat="server">Opt5Value</th>
<th runat="server">Opt6Value</th>
</tr>
<tr id="groupplaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</asp:Content>
It appears you are trying to run a query for each entry in the list view.
If so, you will have to iterate through the list and use something along the lines of (DropDownList)(TypeTemplateLV.Items[{index}].FindControl("DriverObjNameDD")) and manipulate that object in the loop. You cannot access that field without accessing the indexed value of the ListView.
I also noticed you included DriverObjNameDD.DataBind(); twice. You should probably remove one of those.
I have a product catalog page. When you click on the "Add Product" button, page with a cart shows up. This page has a table with an ItemTemplate inside it. Is there any way to get the value from the textBox located inside that ItemTemplate and change the value in the column Total cost in the table by clicking the button? The main problem is that I cannot access the textBox since it's in the . Thank you.
Catalog page:
Cart page:
CartView.aspx
MasterPageFile="~/Page/Store.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="bodyContent" runat="server">
<div id="content" style="margin-left: 7%;">
<style>
#import url("/css/tableCart.css");
#import url("/css/ButtonsCart.css");
</style>
<h2 style="padding: 14px; color:Highlight;">Ваша корзина</h2>
<h3 style="padding: 14px; color:Highlight;">Товары, которые вы добавили в корзину, представлены здесь</h3>
<table id="Table1" V class ="simple-little-table">
<thead>
<tr>
<th></th>
<th>Название</th>
<th>Цвет</th>
<th>Глубина</th>
<th>Ширина</th>
<th>Цена</th>
<th>Количество</th>
<th>Итого</th>
<th></th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="Repeater1" ItemType="Line.Models.CartLine"
SelectMethod="GetCartLines" runat="server" EnableViewState="false">
<ItemTemplate>
<tr>
<td><asp:Image ID="Image1" runat="server" style="height:45px; " ImageUrl=<%# Item.Product.Img %> /></td>
<td> <%# Item.Product.NameProduct %> <%# Item.Product.TypeProducts %></td>
<td><%# Item.Product.Colors %></td>
<td>
Qty: <asp:TextBox ID="txtQty" runat="server" Width="130px" />
<asp:Button ID="cmdUpdate" OnClick="cmdUpdate_Click1" runat="server" Text="Update" CommandName="MyUpdate" CommandArgument = '<%# Container.ItemIndex %>'/>
</td>
<td><%# Item.Size.Depth%></td>
<td><%# Item.Product.Price%></td>
</td>
<td>
<td>
<asp:Label ID="Label2" runat="server" Text="<%# ((Item.Quantity *
Item.Product.Price))%>"></asp:Label>
</td>
<td>
<asp:Label ID="txtAmount" runat="server" Text=""></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
<tfoot>
<tr>
<td colspan="3">Итого:</td>
<td colspan="2" ><%= CartTotal.ToString("c") %></td>
</tr>
</tfoot>
</table>
</div>
</asp:Content>
CartView.aspx.cs
using Line.Helpers;
using Line.Models;
using Line.Models.Repository;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Line.Page
{
public partial class CartView : System.Web.UI.Page
{
protected void Page_Load(object sender, RepeaterCommandEventArgs e)
{
}
public IEnumerable<CartLine> GetCartLines()
{
return SessionHelper.GetCart(Session).Lines;
}
public decimal CartTotal
{
get
{
return SessionHelper.GetCart(Session).ComputeTotalValue();
}
}
public string CheckoutUrl
{
get
{
return RouteTable.Routes.GetVirtualPath(null, "checkout",
null).VirtualPath;
}
}
public string ReturnUrl
{
get
{
return SessionHelper.Get<string>(Session, SessionKey.RETURN_URL);
}
}
protected void cmdUpdate_Click1(object sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "MyUpdate")
{
RepeaterItem rRow = Repeater1.Items[Convert.ToInt32(e.CommandArgument)];
TextBox tQty = (TextBox)rRow.FindControl("txtQty");
Label tAmount = (Label)rRow.FindControl("txtAmount");
tAmount.Text = tQty.Text;
}
}
}
}
Ok, so you can set the index of the button, and pick this up in the Repeater "item command"
So, for your button, you can/want say this:
I have qty, price, and amount in the repeater. and button.
So, the markup can look like this:
Qty: <asp:TextBox ID="txtQty" runat="server" Width="130px" />
<br />
Price: <asp:TextBox ID="txtPrice" runat="server" Width="130px" />
<br />
Amount: <asp:TextBox ID="txtAmount" runat="server" Width="130px" />
<br />
<asp:Button ID="cmdUpdate" runat="server" Text="Update"
CommandName="MyUpdate"
CommandArgument = '<%# Container.ItemIndex %>'/>
So, you are now free to enter Qty, amount in any of the repeated items.
I have this:
Now, my repeater is going accross - and I think you should be using a listview since that better supports a grid + columnar layout - but it really don't mater (listview, gridview, repeater - they all work the same).
So, note how in our button we have both command Name, and command argument. In command argument I pass the row of the repeater.
So, the code looks like this:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// update button in repeater clicked
// update amount based on qty, and price
if (e.CommandName == "MyUpdate")
{
RepeaterItem rRow = Repeater1.Items(e.CommandArgument);
TextBox tQty = rRow.FindControl("txtQty");
TextBox tPrice = rRow.FindControl("txtPrice");
TextBox tAmount = rRow.FindControl("txtAmount");
tAmount.Text = tQty.Text * tPrice.Text;
}
}
So, just pass the "index" of the repeater row as per above. We used this expression as command argument:
<asp:Button ID="cmdUpdate" runat="server" Text="Update"
CommandName="MyUpdate"
CommandArgument = '<%# Container.ItemIndex %>'/>
So, once you have the Item Index (row index), then you can run code against the one row and change that row as per above.
Edit:
So the full markup I have is this:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="border-style:solid;color:black;width:250px;float:left">
<div style="padding:5px;text-align:right">
Hotel Name: <asp:TextBox ID="txtHotelName" runat="server" Text ='<%# Eval("HotelName") %>' Width="130px" />
<br />
First Name: <asp:TextBox ID="txtFirst" runat="server" Text ='<%# Eval("FirstName") %>' Width="130px" />
<br />
Last Name: <asp:TextBox ID="txtLast" runat="server" Text ='<%# Eval("LastName") %>' Width="130px" />
<br />
Qty: <asp:TextBox ID="txtQty" runat="server" Width="130px" />
<br />
Price: <asp:TextBox ID="txtPrice" runat="server" Width="130px" />
<br />
Amount: <asp:TextBox ID="txtAmount" runat="server" Width="130px" />
<br />
<asp:Button ID="cmdUpdate" runat="server" Text="Update" CommandName="MyUpdate" CommandArgument = '<%# Container.ItemIndex %>' />
<div>
City : <asp:DropDownList ID="cboCity" runat="server" DataTextField="City"
DataValueField="City" Width="110px">
</asp:DropDownList>
<div style="float:right;text-align:center;margin-left:4px;">
<asp:Button ID="cmdAddCity" runat="server" Text="+" OnClick="cmdAddCity_Click" Height="16px" Width="12px" Font-Size="XX-Small" cssclass="btnPad" OnClientClick="AddCity();return false"/>
</div>
</div>
Active: <asp:CheckBox ID="chkActive" runat="server" Checked = '<%# Eval("Active") %>'/>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
The code to load up this repeater is this:
protected void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack == false)
LoadGrid();
}
public void LoadGrid()
{
cmdSQL.Connection.Open();
strSQL = "SELECT ID, FirstName, LastName, HotelName, City, Active from tblHotels ORDER BY HotelName";
using (SqlCommand cmdSQL = new SqlCommand(strSQL, new SqlConnection(My.Settings.TEST3)))
{
cmdSQL.Connection.Open();
rstTable.Load(cmdSQL.ExecuteReader);
Repeater1.DataSource = rstTable;
Repeater1.DataBind();
}
}
so the above fills out the repeater - as noted, for a grid like layout, I would use a listview. Drag a list view into a web page.
use the wizards to connect to the database. Now blow out all the templates, only leave the itemtemplate.
Your code to load up the grid - same as above.
now, in place of the repeater as per previous screen shots?
You get this:
So your multiple lines that your building? They should be based on and around a listview. And each row can thus be grabbed, and addressed just as I did per above.
Do a google for listview examples - there is a like a billion examples.
Once you have this setup, then each row is a "thing" that repeats for you automatic based on the data from the table.
The markup for the list view - it again quite much follows the same ideas and concepts as a repeator. the listview for above looks like this:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID">
<ItemTemplate>
<tr style="">
<td><asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /></td>
<td><asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /></td>
<td><asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td><asp:Label ID="HotelNameLabel" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' /></td>
<td><asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%# Eval("Active") %>' Enabled="false" /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">ID</th>
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">Active</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
In past, i worked on ListViews (.net 2.0) using a custom Template field but what i am trying to achieve here is the following
I am now working on .net 4.6
So basically a list which shows items like above and on mouse-hover few options show up as shown in the following screenshot
I also have to trigger those option to do different things -
How can I do that in asp.net, may I please have some code references.
Cheers
P.S.
This is a rough example of how i am creating the List Item Template (as requested)
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<table >
<tr>
<td ><asp:Image ID="image1" ImageUrl='<%# Bind("url") %>' runat="server" Width="98px" /> </td>
<td><h2><asp:Label ID="_label" runat="server" Text ='<%# Bind("title") %>'></asp:Label></h2><asp:Label ID="Label1" runat="server" Text ='<%# Bind("description") %>'></asp:Label></td>
</tr>
</table>
</AlternatingItemTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<table >
<tr>
<td ><asp:Image ID="image1" ImageUrl='<%# Bind("url") %>' runat="server" Width="98px" /> </td>
<td><h2><asp:Label ID="_label" runat="server" Text ='<%# Bind("title") %>'></asp:Label></h2><asp:Label ID="Label1" runat="server" Text ='<%# Bind("description") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<ul id="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
I can add any html formatting to this template e,g i can add ASP:button etc but i don't know how to trigger those to perform certain tasks.
One easy way to achieve your requirement is to keep those buttons there but invisible and show them up when the parent container is hovered. following as a quick sample
aspx
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<tr class="row-data">
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
<asp:Label ID="PositionLabel" runat="server" Text='<%# Eval("Position") %>' />
</td>
<td>
<div class="btn-area">
<asp:Button runat="server" Text="Button1" />
<asp:Button runat="server" Text="Button2" />
</div>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
Name
</th>
<th runat="server">
Position
</th>
<th>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
css
.btn-area
{
display: none;
}
.row-data:hover .btn-area
{
display: block;
}
code-behind
protected void Page_Load(object sender, EventArgs e)
{
ListView1.DataSource = new List<dynamic>() {
new { Name = "Andy", Position = "PG"},
new { Name = "Bill", Position = "SD"},
new { Name = "Caroline", Position = "Manager"}
};
ListView1.DataBind();
}
UPDATE
ListView ItemCommand can capture the postback by button pressed and CommandName makes you able to recognize which button fired it.
<asp:Button runat="server" Text="Button1" CommandName="c1" />
<asp:Button runat="server" Text="Button2" CommandName="c2" />
code-behind
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "c1")
{
// do something when button1 pressed
}
else if (e.CommandName == "c1")
{
// do something when button2 pressed
}
}
I have following datalist:
<asp:DataList ID="dlOrgImages" runat="server"
Width="100%" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<table width="98%">
<tr>
<td>
<asp:Image ID="imgLogo" ImageUrl='OrgImages/<%# Eval("Logo") %>' runat="server" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdLogoSelect" runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
I am binding it through code:
private void BindOrgLogo()
{
dlOrgImages.DataSource= obj.GetDataTable("select idOrg,Title,Logo from Organization order by idOrg");
dlOrgImages.DataBind();
}
obj.GetDataTable(...) is giving me correct datatable.
But datalist is not getting bound. Its not showing me anything.
What can be the problem???
Please help me.
I have a listview control and in layout template, i have linkbuttons. Now what i want to do. i have a span with each linkbutton. i want to give css class while we click on linkbutton. my html code is as follow:
<asp:ListView ID="lst_CallType" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_CallType_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left" width="500px">
<asp:LinkButton ID="lnk_Name" runat="server" ValidationGroup="vgSearch" OnClientClick="changeSortState();"
CommandArgument="tblCallTypenew.CallType" OnClick="lnk_Sort">Name</asp:LinkButton>
<span id="imgSortPosition" class="sortNotSelected"></span>
</td>
<td align="left" width="80px">
<asp:LinkButton ID="lnk_Status" runat="server" CommandArgument="tblCallTypenew.isactive"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Status</asp:LinkButton>
<span id="Span1" class="sortNotSelected"></span>
</td>
<td align="left" width="200px">
<asp:LinkButton ID="lnk_CreatedOn" runat="server" CommandArgument="tblCallTypenew.CreatedDate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Created On</asp:LinkButton>
<span id="Span2" class="sortNotSelected"></span>
</td>
<td align="left" width="200px">
<asp:LinkButton ID="lnk_LastModfiedOn" runat="server" CommandArgument="tblCallTypenew.ModifiedDate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified On</asp:LinkButton>
<span id="Span3" class="sortNotSelected"></span>
</td>
<td align="left" width="200px">
<asp:LinkButton ID="lnk_CreatedBy" runat="server" CommandArgument="tblUserNew.FirstName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Created By</asp:LinkButton>
<span id="Span4" class="sortNotSelected"></span>
</td>
<td align="left" width="200px">
<%--<asp:LinkButton ID="lnkCreatedDate" runat="server" CommandArgument="tblUserActivities.CreatedDate"
OnClick="lnk_Sort">Created Date</asp:LinkButton>--%>
<asp:LinkButton ID="lnk_LastModfiedBy" runat="server" CommandArgument="v.FirstName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Modified By</asp:LinkButton>
<span id="Span5" class="sortNotSelected"></span>
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Activity
<div style="width: 50px; float: right;">
</div>
</td>
</tr>
<tr id="tr" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "EvenRowColor" : "OddRowColor" %>'>
<td align="left">
<asp:Label ID="lblDeptId" runat="server" Text='<%# Eval("ID")%>' Visible="false"></asp:Label>
<%# Eval("Calltype")%>
</td>
<td align="left">
<asp:Label ID="lbl_Status" runat="server" Style="display: none;" Text='<%# Eval("IsActive")%>'></asp:Label>
<asp:ImageButton ID="imgbtnStatus" runat="server" CommandArgument='<%# Eval("id") %>'
OnClick="imgbtnStatus_Onclick" />
</td>
<td align="left">
<%# Eval("CreatedDate")%>
</td>
<td align="left">
<%# Eval("ModifiedDate") %>
</td>
<td align="left">
<%# Eval("CreatedBy")%>
</td>
<td align="left">
<%# Eval("ModifiedBy")%>
</td>
<td>
<asp:Label ID="lblCallType" runat="server" Style="display: none;" Text='<%# Eval("Calltype")%>'></asp:Label>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/edit.png"
ToolTip="Edit Details" CommandArgument='<%# Eval("ID") %>' OnClick="imgbtnEdit_OnClick" />
<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
ToolTip="Delete" Style="display: none;" CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete the Call type?');"
OnClick="imgbtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Actually i want to show sort images while user click on linkbuttons.And i want to do it by code behind.
My .cs code is as follow:
protected void lnk_Sort(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
string arg = lnk.CommandArgument.ToString();
ViewState["sortCol"] = arg;
GetSortDirection();
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), Pager.PageSize);
}
private void GetSortDirection()
{
if (Convert.ToString(ViewState["sortDir"]) == "Desc")
{
ViewState["sortDir"] = "asc";
}
else
{
ViewState["sortDir"] = "Desc";
}
}
You can do a findcontrol in Listview_sorting event
i have done it with a silly trick
my html code is:
<asp:ListView ID="lst_CallType" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_CallType_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td width="35px" align="left">
S.No
</td>
<td align="left" width="300px">
<asp:LinkButton ID="lnk_Name" runat="server" ValidationGroup="vgSearch" CommandArgument="tblCallTypenew.CallType"
OnClick="lnk_Sort">Name</asp:LinkButton>
<asp:Image ID="img_lnk_Name" Visible="false" runat="server" />
</td>
<td align="left" width="150px">
<asp:LinkButton ID="lnk_CreatedBy" runat="server" CommandArgument="tblUserNew.FirstName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Created By</asp:LinkButton>
<asp:Image ID="img_lnk_CreatedBy" Visible="false" runat="server" />
</td>
<td align="left" width="120px">
<asp:LinkButton ID="lnk_CreatedOn" runat="server" CommandArgument="tblCallTypenew.CreatedDate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Created On</asp:LinkButton>
<asp:Image ID="img_lnk_CreatedOn" Visible="false" runat="server" />
</td>
<td align="left" width="150px">
<%--<asp:LinkButton ID="lnkCreatedDate" runat="server" CommandArgument="tblUserActivities.CreatedDate"
OnClick="lnk_Sort">Created Date</asp:LinkButton>--%>
<asp:LinkButton ID="lnk_LastModfiedBy" runat="server" CommandArgument="v.FirstName"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified By</asp:LinkButton>
<asp:Image ID="img_lnk_LastModfiedBy" Visible="false" runat="server" />
</td>
<td align="left" width="120px">
<asp:LinkButton ID="lnk_LastModfiedOn" runat="server" CommandArgument="tblCallTypenew.ModifiedDate"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified On</asp:LinkButton>
<asp:Image ID="img_lnk_LastModfiedOn" Visible="false" runat="server" />
</td>
<td align="center" width="55px">
<asp:LinkButton ID="lnk_Status" runat="server" CommandArgument="tblCallTypenew.isactive"
ValidationGroup="vgSearch" OnClick="lnk_Sort">Status</asp:LinkButton>
<asp:Image ID="img_lnk_Status" Visible="false" runat="server" />
</td>
<td align="center" width="50px" style="border-right: 1px solid #6398cc">
Activity
<%-- <div style="width: 50px; float: right;">
</div>--%>
</td>
</tr>
<tr id="tr" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "EvenRowColor" : "OddRowColor" %>'>
<td align="left" valign="middle">
<%# Container.DataItemIndex+1 %>.
</td>
<td align="left">
<asp:Label ID="lblDeptId" runat="server" Text='<%# Eval("ID")%>' Visible="false"></asp:Label>
<%# Eval("Calltype")%>
</td>
<td align="left">
<%# Eval("CreatedBy")%>
</td>
<td align="left">
<%# Convert.ToDateTime(Eval("CreatedDate")).ToString("MMM dd, yyyy")%>
</td>
<td align="left">
<%# Eval("ModifiedBy")%>
</td>
<td align="left">
<%# Convert.ToDateTime(Eval("ModifiedDate")).ToString("MMM dd, yyyy")%>
</td>
<td align="center">
<asp:Label ID="lbl_Status" runat="server" Style="display: none;" Text='<%# Eval("IsActive")%>'></asp:Label>
<asp:ImageButton ID="imgbtnStatus" runat="server" CommandArgument='<%# Eval("id") %>'
OnClick="imgbtnStatus_Onclick" />
</td>
<td class="last" align="center">
<asp:Label ID="lblCallType" runat="server" Style="display: none;" Text='<%# Eval("Calltype")%>'></asp:Label>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/edit.png"
ToolTip="Edit Details" CommandArgument='<%# Eval("ID") %>' OnClick="imgbtnEdit_OnClick" />
<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
ToolTip="Delete" Style="display: none;" CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete the Call type?');"
OnClick="imgbtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
My code behind code is:
protected void lnk_Sort(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
string arg = lnk.CommandArgument.ToString();
ViewState["sortCol"] = arg;
GetSortDirection();
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), Pager.PageSize);
string name = lnk.ID;
Image img = (Image)(lst_CallType.FindControl("img_" + name));
if (img != null)
{
SetSortOrderImage(img, ViewState["sortDir"].ToString());
}
}
private void SetSortOrderImage(Image image, String sortorder)
{
if (sortorder == "asc")
{
image.Visible = true;
image.ImageUrl = "../App_Themes/ThemeNew2/images/up.png";
}
else if (sortorder == "Desc")
{
image.Visible = true;
image.ImageUrl = "../App_Themes/ThemeNew2/images/down.png";
}
}