I have a listview in asp.net like this:
<asp:ListView ID="lvLoads" DataKeyNames="BookingId" OnItemCommand="lvLoads_OnItemCommand" runat="server">
<EmptyDataTemplate>
<table>
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<GroupTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</GroupTemplate>
<ItemTemplate>
<fieldset>
<table class="table table-striped table-responsive">
<thead>
<tr class="hidden-lg">
<th width="15%">Type</th>
<th width="31%">Details</th>
<th width="25%">Distance/Duration</th>
<th width="21%"> </th>
</tr>
</thead>
<tbody>
<tr>
<td width="15%">
<asp:Label CssClass="hide" ID="lblBokingId" runat="server"><%# Eval("BookingId") %></asp:Label>
<asp:Label ID="lblLoadTypeName" runat="server"> <%# Eval("LoadTypeName") %></asp:Label>
<br>
</td>
<td width="21%">
<asp:LinkButton ID="btnViewMore" CssClass="btn btn-warning" CommandName="ViewMore" runat="server">View More</asp:LinkButton>
</td>
</tr>
</tbody>
</table>
</fieldset>
</ItemTemplate>
</asp:ListView>
Now on click of the button ViewMore i wrote this code to extract listviewItem's value:
var id = ((Label)e.Item.FindControl("lblBookingId")).Text;
var name = ((Label)e.Item.FindControl("lblLoadTypeName")).Text;
But e.Item.FindControl("lblBookingId") always comes null. I checked the page's html by using inspect element of chrome, and i was shocked to see that my id somehow got changed to ContentSection_ctl00_lblLoadTypeName_0
I am really stuck at this. Please help me. Thanx in Advance
I had done some work with your list view and one which i had created to resemble the problem.
Default2.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
WORKING EXAMPLE
<asp:ListView ID="lvLoads" runat="server">
<LayoutTemplate>
<table border="0" cellpadding="1">
<tr style="background-color: #E5E5FE">
<th align="left">EmployeeId
</th>
<th align="left">LastName
</th>
<th align="left"></th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<asp:Label ID="lblCustomerID" runat="server" Text='<%# Eval("BookingId") %>'></asp:Label>
</td>
<td id="Td2" runat="server">
<asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LoadTypeName") %>'></asp:Label>
</td>
<td id="Td3" runat="server">
<asp:LinkButton ID="lnkSelect" runat="server" OnClick="btnViewMore_Click" Text="Select" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
<div>
ERROR
<asp:ListView ID="ListView1" DataKeyNames="BookingId" OnItemCommand="lvLoads_OnItemCommand" runat="server">
<EmptyDataTemplate>
<table>
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<GroupTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</GroupTemplate>
<ItemTemplate>
<fieldset>
<table class="table table-striped table-responsive">
<thead>
<tr class="hidden-lg">
<th width="15%">Type</th>
<th width="31%">Details</th>
<th width="25%">Distance/Duration</th>
<th width="21%"> </th>
</tr>
</thead>
<tbody>
<tr>
<td width="15%">
<asp:Label CssClass="hide" ID="lblBokingId" runat="server"><%# Eval("BookingId") %></asp:Label>
<asp:Label ID="lblLoadTypeName" runat="server"> <%# Eval("LoadTypeName") %></asp:Label>
<br>
</td>
<td width="21%">
<asp:LinkButton ID="btnViewMore" CssClass="btn btn-warning" OnClick="btnViewMore_Click1" runat="server">View More</asp:LinkButton>
</td>
</tr>
</tbody>
</table>
</fieldset>
</ItemTemplate>
</asp:ListView>
</div>
</div>
</form>
Default2.aspx.cs:
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 obj = new Class1();
lvLoads.DataSource = obj.bind();
lvLoads.DataBind();
ListView1.DataSource = obj.bind();
ListView1.DataBind();
}
protected void lvLoads_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
}
protected void btnViewMore_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
ListViewDataItem item = (ListViewDataItem)(sender as Control).NamingContainer;
Label lblStatus = (Label)item.FindControl("lblLastName");
string message = lblStatus.Text;
}
protected void btnViewMore_Click1(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
ListViewDataItem item = (ListViewDataItem)(sender as Control).NamingContainer;
Label lblStatus = (Label)item.FindControl("lblLoadTypeName");
string message = lblStatus.Text;
}
}
Class1:
public class Class1
{
public int BookingId { get; set; }
public string LoadTypeName { get; set; }
public Class1()
{
}
public List<Class1> bind()
{
List<Class1> data = new List<Class1>();
Class1 obj = new Class1();
obj.BookingId = 1;
obj.LoadTypeName = "Type name1";
data.Add(obj);
obj = new Class1();
obj.BookingId = 2;
obj.LoadTypeName = "Type name2";
data.Add(obj);
obj = new Class1();
obj.BookingId = 3;
obj.LoadTypeName = "Type name3";
data.Add(obj);
obj = new Class1();
obj.BookingId = 4;
obj.LoadTypeName = "Type name4";
data.Add(obj);
return data;
}
}
As you can see in both list view there is only problem related with design which you are using in your list view. Please change design as per your requirement.
You are placing control in further other controls that's why id will change at run time.
hope it will help you.
I want to create dynamic 2 textbox and 2 dropdownlist below each textbox and dropdownlist in button click. This is the code i am using which creates dynamic textbox and dropdownlist but its creating control in horizontal way.I want creation of dynamic controls in a vertical manner which will be coming under textbox and dropdown.
<div id="dvContainer" runat="server">
<table align="center" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td>
<table width="100%">
<tr>
<td align="center">Date</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="150px"> </asp:TextBox>
</td>
<td align="center">Time</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Width="150px"></asp:TextBox>
</td>
<td align="center">Godown</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="150px">
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table width="100%">
<tr>
<td align="center">Item</td>
<td align="center">QTY</td>
<td align="center">Unit</td>
<td align="center">Available</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">
<asp:DropDownList ID="DropDownList2" runat="server" Width="150px">
</asp:DropDownList>
</td>
<td align="center">
<asp:TextBox ID="TextBox3" runat="server" Width="150px"></asp:TextBox>
</td>
<td align="center">
<asp:DropDownList ID="DropDownList3" runat="server" Width="150px">
</asp:DropDownList>
</td>
<td align="center">
<asp:TextBox ID="TextBox4" runat="server" Width="150px"></asp:TextBox>
</td>
<td align="center">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</td>
</tr>
</table></td>
</tr>
</table>
</div>
This is the code i am using in cs page
public partial class StockEntry : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList Ddl_Item;
protected System.Web.UI.WebControls.TextBox Txt_Quantity;
protected System.Web.UI.WebControls.DropDownList Ddl_Unit;
protected System.Web.UI.WebControls.TextBox Txt_Available;
protected void Page_Load(object sender, EventArgs e)
{
}
int countTimes = 0;
protected void Button1_Click(object sender, EventArgs e)
{
if (ViewState["countTimes"] == null)
{
countTimes = 1;
}
else
{
countTimes = Convert.ToInt32(ViewState["countTimes"]);
}
for (int i = 0; i < countTimes; i++)
{
Ddl_Item = new DropDownList();
Ddl_Item.ID = "Ddl_Item" + i;
Ddl_Item.Width = 180 + i;
Txt_Quantity = new TextBox();
Txt_Quantity.ID = "Txt_Quantity" + i;
Txt_Quantity.Width = 180 + i;
Ddl_Unit = new DropDownList();
Ddl_Unit.ID = "Ddl_Unit" + i;
Ddl_Unit.Width = 180 + i;
Txt_Available = new TextBox();
Txt_Available.ID = "Txt_Available" + i;
Txt_Available.Width = 180 + i;
dvContainer.Controls.Add(Ddl_Item);
dvContainer.Controls.Add(Txt_Quantity);
dvContainer.Controls.Add(Ddl_Unit);
dvContainer.Controls.Add(Txt_Available);
}
countTimes = countTimes + 1;
ViewState.Add("countTimes", countTimes);
}
}
You are adding your controls in the div, not in the table and next to each other. To add some html structure around controls, you can create literal object with your html in its text, and add them before/after your controls (for example you can add <br/> )
I think what you want is HtmlGenericControl http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol.aspx
This will allow you to add the table that you require to set your layout, you could of course wrap each control in a div and control your layout using CSS.
I have a usercontrol that contains a repeater. Within this repeater there is an ImageButton, that when clicked is supposed to call an expand method. However, the ImageButton is not firing anything, not even a PostBack.
AutoEventWireUp on the usercontrol is set to true. the Repeater ItemDataBound is set in Markup. But even with all of that the ImageButton still will not fire any type of action.
What would be the reason that no firing is occuring at all?
Below is the HTML Markup:
<%# Control Language="vb" AutoEventWireup="true" Codebehind="BiddersGroupList.ascx.vb"
Inherits="FXWB.BidPackage.BiddersGroupList" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<%# Register TagPrefix="fxwb" TagName="GridLabel" Src="~/Secure/Controls/GridLabel.ascx" %>
<telerik:RadCodeBlock ID="rcbScripts" runat="server">
<script>
function pb(ctrl,FolderId, B, BID, CID)
{
// debugger;
var lblid = ctrl.parentElement.parentElement.cells[7].childNodes[0].id;
SethdnUpdatedValues(lblid, (B=='WB') ? 'Yes' : 'No');
NoRefreshRequestProcessor_SendRequest('changeBidStatus:'+B+':'+BID+':'+CID);
}
function ir(ctrl,FolderId, BID, CID)
{
debugger;
if(ctrl.checked ==true)
B = '1';
else
B = '0';
NoRefreshRequestProcessor_SendRequest('changeAdminIsRceived:'+B+':'+BID+':'+CID);
}
function pw(BPID, SUID, FID){
var BID ='Owner';
window.open('Bidpackage/ReplyToBid.aspx?BPID='+ BPID + '&SUID='+SUID+'&BID='+BID + '&FID='+ FID + '&a=edit','_blank','height=600,width=800,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes, resizable = yes');
}
function be(BID, BPID,CSI){
window.open('Bidpackage/EditBidderInfo.aspx?BidderID='+BID+'&BidPackageID='+BPID+'&CSI='+CSI,'bidder_edit','height=550,width=950,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes, resizable = yes')
}
function one(sender,NID,CsiValue,lblid){
//debugger;
NoteLabelID=lblid;
var url = 'Bidpackage/BidderNoteEdit.aspx?NoteID='+escape(NID)+'&CSI='+CsiValue;
var Top = (screen.availHeight / 2) - 100; //getY(sender) - document.getElementById('FolderBody').scrollTop + 226;
var Left = (screen.availWidth / 2) - 150; //getX(sender) + 280;
var params = 'height=200, width=300, location=0, top='+Top+', left='+Left+', status=0, scrollbars=0, toolbar=0';
var arr=NID.split(':');
window.open(url,'BDR_NOTE_'+escape(arr[0]),params);
//window.open(url,'BDR_NOTE_'+escape(NID.replace(':','_')),params);
//window.open(url,params);
}
function SelectAll(chkMain)
{
//debugger;
var mainchk = chkMain.getAttribute("Division");
var chk = document.documentElement.getElementsByTagName("input");
var i;
for(i=0;i<chk.length; i++)
{
if(chk[i].type=='checkbox')
{
csiChild = chk[i].getAttribute("Division");
if (csiChild != null)
{
if(csiChild == mainchk)
{
if(chkMain.checked == true)
{
chk[i].checked = true;
SelectCodes(chk[i])
}
else
{
chk[i].checked = false;
SelectCodes(chk[i])
}
}
}
}
}
}
function SelectCodes(chkMain)
{
// debugger;
var mainchk = chkMain.getAttribute("CSI");
var chk = document.documentElement.getElementsByTagName("input");
var i;
for(i=0;i<chk.length; i++)
{
if(chk[i].type=='checkbox')
{
csiChild = chk[i].getAttribute("CSI");
if (csiChild != null)
{
if(csiChild == mainchk)
{
if(chkMain.checked == true)
{
chk[i].checked = true;
}
else
{
chk[i].checked = false;
}
}
}
}
}
}
function CheckAllBidders(chkMain)
{
// debugger;
var mainCSI = chkMain.getAttribute("CSI");
var csi;
var csiChild;
var bidder;
var chkChildID;
var chk = document.documentElement.getElementsByTagName("input");
var i;
for(i=0;i<chk.length; i++)
{
if(chk[i].type=='checkbox')
{
// chkChildID = chk[i].id;
// s = chkChildID.indexOf(":");
csiChild = chk[i].getAttribute("CSI");
bidder = chk[i].getAttribute("Bidder");
if (csiChild != null && bidder != null)
{
if(csiChild==mainCSI)
{
// debugger;
if(chkMain.checked == true)
{
chk[i].checked = true;
}
else
{
chk[i].checked = false;
}
}
}
}
}
}
var btnReloadExpandedID = '<%=ButtonReloadExpanded.ClientID %>';
var hdnExpandBidderID = '<%=hdnExpandBidder.ClientID %>';
var btnBindBiddingStatus = '<%=ButtonBindBiddingStatus.ClientID %>';
var btnBindNotes = '<%=ButtonBindNotes.ClientID %>';
var hdnNoteCSI = '<%=hdnNoteCSI.ClientID %>';
var hdnCSIId1 = '<%=hdnCSIId1.ClientID %>';
var hdnExpandCSIs = '<%=hdnCSIIs.ClientID %>';
var NoteLabelID;
</script>
<script>
function BindNote(csivalue1,note)
{
// var ButtonBindNotes1 = document.getElementById(btnBindNotes);
// var HiddenNotesCSI1 = document.getElementById(hdnNoteCSI);
// HiddenNotesCSI1.value = csivalue1;
// ButtonBindNotes1.click();
document.getElementById(NoteLabelID).innerHTML = note;
SethdnUpdatedValues(NoteLabelID,note);
}
function SethdnUpdatedValues(id,value)
{
//debugger;
if (id!=undefined)
{
var hdnUpdatedValues = document.getElementById('<%=hdnUpdatedValues.ClientID %>');
if(hdnUpdatedValues.value!="")
if(hdnUpdatedValues.value.indexOf(id) !=-1)
{
var st = hdnUpdatedValues.value.indexOf(id);
var end = hdnUpdatedValues.value.indexOf("|~|",st);
var valToReplace = hdnUpdatedValues.value.substring(st,end);
var valReplaceBy = id + "=" + value;
hdnUpdatedValues.value = hdnUpdatedValues.value.replace(valToReplace, valReplaceBy);
}
else
hdnUpdatedValues.value = hdnUpdatedValues.value + id + '=' + value + '|~|';
else
hdnUpdatedValues.value = id + '=' + value + '|~|';
}
}
function SetUpdatedValues()
{
//debugger;
try
{
var hdnUpdatedValues = document.getElementById('<%=hdnUpdatedValues.ClientID %>');
if (hdnUpdatedValues.value != "")
{
var values = hdnUpdatedValues.value.split('|~|');
var ctrlValue;
var i;
for(i=0; i<values.length-1;i++)
{
ctrlValue = values[i].split('=');
document.getElementById(ctrlValue[0]).innerHTML = ctrlValue[1];
}
}
}
catch(ex)
{
}
}
</script>
</telerik:RadCodeBlock>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DynamicLayout="true">
<ProgressTemplate>
<div style="background-color: White; position: absolute; z-index: 10; left: expression((this.offsetParent.clientWidth/2)-(this.clientWidth/2)+this.offsetParent.scrollLeft);
top: expression((this.offsetParent.clientHeight/2)-(this.clientHeight/2)+this.offsetParent.scrollTop);">
<img src="../Images/LoadingIcon.gif" height="80" width="150" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePannel1" runat="server">
<ContentTemplate>
<%--<script type="text/javascript" language=javascript>
function ShowData()
{
var trValues = document.getElementById('<%=trRptrDivision.ClientID %>');
trValues.style.visibility="visible";
}
</script>--%>
<asp:HiddenField ID="hdnUpdatedValues" runat="server" />
<script language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
SetUpdatedValues();
}
</script>
<asp:Label ID="lblTestStatus" runat="server"></asp:Label>
<input type="button" id="ButtonReloadExpanded" runat="server" style="display: none;"
value="Reload Expanded" />
<input type="button" id="ButtonBindBiddingStatus" runat="server" style="display: none;"
value="Bind BiddingStatus" />
<input type="button" id="ButtonBindNotes" runat="server" style="display: none;" value="Bind Notes" />
<asp:HiddenField ID="hdnExpandBidder" runat="server" />
<asp:HiddenField ID="hdnNoteCSI" runat="server" />
<asp:HiddenField ID="hdnCSIId1" runat="server" />
<asp:HiddenField ID="hdnCSIIs" runat="server" />
<table border="1" cellpadding="0" cellspacing="0" style="background: skyblue; border-style: solid;
border-width: 1px; border-color: black;" width="100%" id="tblBiddersList">
<tr>
<td colspan="3">
<asp:Label ID="lblError" runat="server" Font-Size="8pt" ForeColor="Red" Font-Bold="True"
EnableViewState="False" Font-Names="Arial"></asp:Label>
</td>
</tr>
<asp:Repeater ID="rptdivision" runat="server" EnableViewState="true" OnItemDataBound="rptdivision_ItemDataBound">
<HeaderTemplate>
<tr>
<td class="MasterHeader">
<asp:Button ID="ButtonExpandCollapse" UseSubmitBehavior="false" runat="server" Text="Expand All" CssClass="button"
CommandName="ExpandCollapse" />
Divisions
</td>
<td class="MasterHeader">
Divisions Description
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color: #66cc99;">
<td>
<input type="checkbox" id="chkDivision" biddercount='<%#DataBinder.Eval(Container, "DataItem.countBidders")%>'
runat="server" onclick="javascript:SelectAll(this);" />
<%-- <asp:CheckBox ID="chkDivision" runat="server" onclick="javascript:SelectAll(this);" />--%>
<asp:ImageButton runat="server" ID="ImageButton1" CommandName="ExpandDivision" ImageUrl="~/Secure/Images/plus_big.gif" />
<asp:Label ID="lbDivisionName" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.classifier_name")%>'></asp:Label>
<%-- <asp:HiddenField ID="hfcgroup" runat="server" Value='<%#DataBinder.Eval(Container, "DataItem.csigroup")%>' />--%>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.classifier_description")%>'></asp:Label>
</td>
</tr>
<tr class="trup" id="trRptrDivision" runat="server" style="background: white;">
<td>
<asp:Repeater ID="rptrBidPackage" runat="server" OnItemCommand="rptrBidPackage_ItemCommand">
<%--<HeaderTemplate>
<tr>
<td class="MasterHeader">
<asp:Button ID="ButtonExpandCollapse" runat="server" Text="Expand All" CssClass="button"
CommandName="ExpandCollapse" />
CSI Code
</td>
<td class="MasterHeader">
CSI Description
</td>
</tr>
</HeaderTemplate>--%>
<ItemTemplate>
<tr class="trup" style="margin: 0px 0px 0px 0px; height: 0%; display: none" id="trMaster"
runat="server">
<td class="tdupMaster">
<asp:ImageButton runat="server" ID="ImageColapseExpand" CommandName="Expand" CommandArgument='<%#DataBinder.Eval(Container, "DataItem.CSIValue")%>'
ImageUrl="~/Secure/Images/plus_big.gif" />
<b>
<input type="checkbox" id="chkCodes" biddercount='<%#DataBinder.Eval(Container, "DataItem.countBidders")%>'
runat="server" onclick="javascript:SelectCodes(this);" />
<%-- <asp:CheckBox ID="chkCodes" runat="server" onclick="javascript:CheckCodes();" /> --%>
<asp:Label ID="LabelCSI" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.CSIValue")%>'></asp:Label>
</b>
</td>
<td class="tdupMaster">
<em>
<%#DataBinder.Eval(Container, "DataItem.CSIDesc")%>
</em>
</td>
</tr>
<tr class="trup" id="trRptrBidders" runat="server" style="background: white; display: none">
<td colspan="2">
<table border="1" width="100%" cellpadding="1" cellspacing="1" style="background: #eeeeee;">
<asp:Repeater ID="rptrBidders" runat="server" EnableViewState="true" OnItemDataBound="rptrBidders_ItemCreated">
<HeaderTemplate>
<tr style="background: #cccccc; color: #205f7d; font-weight: bold; font-size: x-small;"
class="DetailHeader">
<td class="DetailHeader" align="right">
<input type="checkbox" id="chkSelectAll" runat="server" onclick="javascript:CheckAllBidders(this);" />
</td>
<td class="DetailHeader">
Action
</td>
<td class="DetailHeader">
Company name
</td>
<td class="DetailHeader">
Contact
</td>
<td class="DetailHeader">
Phone
</td>
<td class="DetailHeader">
Fax
</td>
<td class="DetailHeader">
Email</td>
<td class="DetailHeader">
Will Bid</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="trup" runat="server" id="trBidder">
<td rowspan="2" style="width: 50px;" id="tdCheckBox" align="right">
<asp:Label runat="server" ID="lblIsReceived" Text="+" Font-Bold="true" Visible="false"></asp:Label>
<input type="checkbox" id="chkBidder" runat="server" />
<input type="hidden" runat="server" id="hdnFaxStatus" value='<%#DataBinder.Eval(Container, "DataItem.FaxStatus")%>' />
<input type="hidden" runat="server" id="hdnIsReceived" value='<%#DataBinder.Eval(Container, "DataItem.IsReceived")%>' />
</td>
<td rowspan="2" style="width: 0%;">
<img style="margin: 0px;" onclick="pw('<%#DataBinder.Eval(Container, "DataItem.BidpackageID")%>','<%#DataBinder.Eval(Container, "DataItem.SiteUserID")%>','<%#DataBinder.Eval(Container, "DataItem.FolderID")%>');"
src="Images/tool_preview.gif" alt="View"></img><img style="margin: 0px;" src="Images/BidPackage/tool_bidder_edit.gif"
alt="Edit Bidder Info" onclick="be('<%#DataBinder.Eval(Container, "DataItem.BidderID")%>','<%#DataBinder.Eval(Container, "DataItem.BidpackageID")%>','<%#DataBinder.Eval(Container, "DataItem.CSIs!2!CSI")%>')"></img><img
style="margin: 0px;" src="Images/BidPackage/tool_approve_f2.gif" alt="Will Bid"
onclick="pb(this,'<%#DataBinder.Eval(Container, "DataItem.FolderID")%>','WB','<%#DataBinder.Eval(Container, "DataItem.BidderID")%>','<%#DataBinder.Eval(Container, "DataItem.CsiID")%>');"></img><img
style="margin: 0px;" src="Images/BidPackage/tool_decline_f2.gif" alt="Will Not Bid"
onclick="pb(this,'<%#DataBinder.Eval(Container, "DataItem.FolderID")%>','NB','<%#DataBinder.Eval(Container, "DataItem.BidderID")%>','<%#DataBinder.Eval(Container, "DataItem.CsiID")%>');"></img><asp:CheckBox
ID="chkIsReceived" ToolTip="Admin IsReceived" runat="server" FolderID='<%#DataBinder.Eval(Container, "DataItem.FolderID")%>'
Checked='<%#DataBinder.Eval(Container, "DataItem.AdminIsReceived")%>' />
</td>
<td class="fn">
<input type="hidden" runat="server" id="hdnBidder" value='<%#DataBinder.Eval(Container, "DataItem.BidderID")%>' />
<input type="hidden" runat="server" id="hdnCsiID" value='<%#DataBinder.Eval(Container, "DataItem.CsiID")%>' />
<%#DataBinder.Eval(Container, "DataItem.Organization")%>
</td>
<td class="fn">
<%#DataBinder.Eval(Container, "DataItem.FullName")%>
</td>
<td class="fn">
<nobr>
<%#DataBinder.Eval(Container, "DataItem.Phone")%>
</nobr>
</td>
<td class="fn">
<nobr>
<%#DataBinder.Eval(Container, "DataItem.Fax")%>
</nobr>
</td>
<td class="fn">
<nobr>
<%#DataBinder.Eval(Container, "DataItem.EMail")%>
</nobr>
</td>
<td class="fn">
<asp:Label ID="lblWillBid" runat="server">
<%#DataBinder.Eval(Container, "DataItem.WillBid")%>
</asp:Label>
</td>
</tr>
<tr id="trBidderNote">
<td colspan="6" style="font-size: xx-small; background-color: #FEFEFE; padding: 0px;">
<span id="spanBidderNote" runat="server" class="Note">Note:</span>
<input type="hidden" runat="server" id="hdnBidderNoteID" value='<%#DataBinder.Eval(Container, "DataItem.BidderNoteID")%>' />
<div style="height: 100%; width: 210px; border: solid 0px gray; display: inline;"
id="note">
<asp:Label ID="lblBidderNote" runat="server">
<%#DataBinder.Eval(Container, "DataItem.BidderNote")%>
</asp:Label>
</div>
<%#DataBinder.Eval(Container, "DataItem.Qualifications")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<%-- <asp:GridView ID="GridViewBidders" runat="server" EnableViewState="true" Visible="false">
</asp:GridView>--%>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>
your repeater is inside the update panel so use trigger of async type like follow:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imagebtn" EventName="CLICK" />
</Triggers>
And make some changes in repeater's code...
<asp:ImageButton runat="server" ID="ImageColapseExpand" onclick="ImageColapseExpand_Click" CommandArgument='<%#DataBinder.Eval(Container, "DataItem.CSIValue")%>'
ImageUrl="~/Secure/Images/plus_big.gif" />
<b>
Create a click event in code behind like bellow:
protected void ImageColapseExpand_Click(object sender, ImageClickEventArgs e)
{
}
Hope this will work for you......
I have a datalist where the huperlinks will be populated with list of article names. When clicking on any article link, i load the content inside tag with ID = "POST"
The problem is, when i click on the link in my datalist, the page refreshed to load the content. How can i solve this ? Thanks
<asp:ScriptManager ID="scm" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td>
<asp:Panel ID="Panel1" runat="server" Width="800">
<div id="divContent" runat="server" class="post">
<table id="tblPost" style="float" border="1" style="border-style: outset; border-width: thin"
width="250" height="200" align="right">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Width="200" Font-Bold="True" Text="Article Sections"></asp:Label>
</td>
</tr>
<tr>
<td align="left">
<asp:DataList ID="DLArticles" runat="server">
<ItemTemplate>
<table id="Table2" visible="true" align="left">
<tr align="left">
<td>
<asp:HyperLink ID="hypSubSections" runat="server" NavigateUrl='<%# "~/News.aspx?FID=" + DataBinder.Eval(Container.DataItem,"FID") + "&CID=" + DataBinder.Eval(Container.DataItem,"CID") %>'
Text='<%# DataBinder.Eval(Container.DataItem,"Title") %>'></asp:HyperLink>
</td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td align="right">
<asp:HyperLink ID="HypViewALL" runat="server">View All</asp:HyperLink>
</td>
</tr>
</table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p id="POST" runat="server">
</p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DLArticles" />
</Triggers>
</asp:UpdatePanel>
</div>
</asp:Panel>
</td>
</tr>
</table>
First of all you need to use data-driven control that allows to use multiple key field names. DataList doesn't has such feature so you need to use GridView or ListView control. As each post idetified with unique combination of FID and CID values set those fields as DataKeyNames. Then, change HyperLink to LinkButton control and set appropriate CommandName property value. After that you need to register each LinkButton as AsyncPostback control (on a page, not in UpdatePanel1's triggers collection) or just wrap whole ListView by an UpdatePanel. Then all you need is to handle SelectedIndexChanged event and update post content.
<asp:UpdatePanel runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:ListView runat="server" ID="ListView1" DataKeyNames="FID,CID">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="text-align: left;">
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" Text='<%# Eval("Title") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<p runat="server" id="POST">
</p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListView1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
private static readonly List<Post> DataSource = new List<Post>
{
new Post{FID = 1, CID = "1", Title="First", Content= Guid.NewGuid().ToString()},
new Post{FID = 2, CID = "1", Title="Second", Content= Guid.NewGuid().ToString()},
new Post{FID = 1, CID = "2", Title="Third", Content= Guid.NewGuid().ToString()},
new Post{FID = 2, CID = "2", Title="Fourth", Content= Guid.NewGuid().ToString()},
};
protected void Page_Init(object sender, EventArgs e)
{
ListView1.SelectedIndexChanging += ListView1_SelectedIndexChanging;
ListView1.SelectedIndexChanged += ListView1_SelectedIndexChanged;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListView1.DataSource = DataSource;
ListView1.DataBind();
}
}
void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
ListView1.SelectedIndex = e.NewSelectedIndex;
}
void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
var dataKey = ListView1.SelectedDataKey;
var fid = (int)dataKey["FID"];
var cid = dataKey["CID"] as string;
var post = DataSource.FirstOrDefault(p => p.FID == fid && p.CID == cid);
if (post != null)
{
POST.InnerText = Server.HtmlEncode(post.Content);
}
}
public class Post
{
public int FID { get; set; }
public string CID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
I want to change background color of the row in particular condition.My code is
<asp:ListView ID="lst_SentItems" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_SentItems_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left" width="180px">
EmpName
</td>
<td align="left" width="180px">
Salary
</td>
<td align="left" width="180px">
Address
</td>
<td align="left" width="180px">
Department
</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="lbl3" runat="server" text='<%# Eval("EmpName")%>' />
</td>
<td align="left">
' />
</td>
<td align="left">
<asp:label id="lbl1" runat="server" text='<%# Eval("Address")%>' />
</td>
<td align="left">
<asp:label id="lbl" runat="server" text='<%# Eval("Department")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Now i want to give color to particular department like if person is from Account dept then the row's background color should be red, if person belongs to IT dept then Back ground color should be green.
I have tried it some code in ItemdataBound but that code changes only the back ground of labels.i want to change the row back ground.That code is
protected void lst_SentItems_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label lblCount = (Label)e.Item.FindControl("lbl");
if (lblCount != null)
{
if (lblCount.Text == IT2")
{
lblCount.BackColor = System.Drawing.Color.Red;
}
}
}
}
Vision check this :It is just an idea and edit it according to your requirement.
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataitem = (ListViewDataItem)e.Item;
int policyid = (int)DataBinder.Eval(dataitem.DataItem, "EmpID");
if (policyid == 3)
{
HtmlTableRow cell = (HtmlTableRow)e.Item.FindControl("MainTableRow");
cell.Style.Add("background-color", "Red");
}
}
}