Imagebutton in a Listview - asp.net

I've got an Imagebutton in my listview, but then I can't type in my code (aspx.cs) in Imagebutton1.Click:
<asp:ListView ID="lvFotos" runat="server"
GroupItemCount="6" InsertItemPosition="LastItem" align="center">
<LayoutTemplate>
<table border="0">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td align="center" height="150px"
style="background-color: #ffffff;color: #ffffff; border:none;" width="142px">
<asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" />
</td>
</ItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
</asp:ListView>
How can I resolve this?

You shoul use listview ItemCommand event.
<asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" CommandName="Fire_click_event" />
 
public void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if(e.CommandName != "Fire_click_event")
{
// Do what you want in click event
}
}

Related

LinkButton OnClick is Not Frie inside Update panal

LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal here is my Code in aspx page I tried using UpdateMode="Conditional" it is not fire and asyncpostback also used it is not fire
<pre>LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal
</pre>
<asp:UpdatePanel ID="Aspx_UpdatePanel_DocumentVersion" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:LinkButton ID="Aspx_LinkButton_DocumentVersion" runat="server" Style="float: right; margin: 2px 5px 2px 0;" CssClass="Label_Text9"
OnClick="LoadDocumentVersion" />
<asp:UpdateProgress runat="server" AssociatedUpdatePanelID="Aspx_UpdatePanel_DocumentVersion"
DynamicLayout="true">
<ProgressTemplate>
<img src="Images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center" style="float: left;">
<tr valign="top">
<td style="padding: 5px;" align="center">
<asp:Repeater ID="Aspx_Repeater_DocumentVersions" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center">
<tr valign="top" align="left" class="border_spacing">
<td class="Heading_border_left_spacing">
<asp:Label ID="Label1" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_FileName %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label2" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Type %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label3" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Size %>" />
</td>
<td class="Heading_border_right_spacing">
<asp:Label ID="Label4" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Created_By %>" />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr valign="middle" align="left" height="25px">
<td class="border_left_spacing">
<a class="Anchor_Text9_Grey" href="DownloadAttachment.aspx?InternalPath=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString () %>&InternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>&ExternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>"
onclick='javascript:SafeHandleURL(this, "DownloadAttachment.aspx", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString ().Replace ( #"\", #"\\" ) %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>" );'>
<asp:Label ID="Label5" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>'
CssClass="Label_Text9" />  </a>
</td>
<td class="border_withoutspacing">
<asp:Label ID="Label6" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["Type"].ToString () %>' /> 
</td>
<td class="border_withoutspacing Label_Text9">
<asp:Label ID="Label7" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["FileSize"].ToString () %>' /> 
<asp:Label ID="Label8" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Bytes %>" /> 
</td>
<td class="border_right_spacing">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedBy"].ToString () %>'
CssClass="Label_Text9" CommandArgument='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedByID"].ToString () %>'
OnCommand="GoToEmployee" /> 
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr height="10px">
<td colspan="3" />
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
CodeBehind.cs
protected void LoadDocumentVersion(object sender, EventArgs e)
{
try
{
string zszFolderID = "";
string zszDocumentID = "";
string zszIsPublic = "";
EMSBLCommon.AddToLog("Document", "CRM", "View Document Versions", "");
string zszUpdateDocument = Aspx_HiddenField_DocumentPath.Value;
string zszDocumentPath = zszUpdateDocument.Substring(0, zszUpdateDocument.LastIndexOf('/'));
string zszDocumentName = zszUpdateDocument.Substring(zszUpdateDocument.LastIndexOf('/') + 1);
zszFolderID = GetFolderID(zszDocumentPath, ref zszIsPublic);
zszDocumentID = EMSBLCRM.GetDocumentID(zszFolderID, zszDocumentName).ToString();
if (!zszDocumentID.Equals("0"))
LoadDocumentAttachments(zszDocumentID);
}
catch (Exception ex)
{
Utilities.SendCrashEMail(ref ex);
}
}
Make sure AutoEventWireup="true" in your Page directive
Make sure you do not get errors, either client-side or server-side. Attach a debugger and step through your code to make sure of that
Your button cannot be clicked as it is because it is invisible, so I assume you invoke the click via JavaScript. To do that for a link button, you need to evaluate its href attribute: eval(document.getElementById("<%=Aspx_LinkButton_DocumentVersion.ClientID%>").getAttribute("href"));
make sure all webresource requests pass (i.e., 200 or 300s status codes). This is how the MS AJAX frameworks is fetched.
Make sure your script manager is the first control after the <form> tag and that all subsequent AJAX-enabled stuff is inside the <form> as well.

How to display the multiple details in a single listbox in asp

I searched over Google i didn't get my Requirement
My Output Like
Now I want to Display Like
How to do?
I have Two tables Like SystemUsers and UserSoftware Details
SystemUsers table Having SystemUserName,DepartmentId,SystemId,SystemUserId
UserSoftwareDetails Having UserSwDetId,SystemUserId,Software,SoftwareKey
My Aspx Coding Like
<asp:ListView ID="ListView1" runat="server" GroupItemCount="3" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td >
<table cellpadding="2" frame="box" cellspacing="0" border="1" style="width: 300px; height: 150px; ">
<tr>
<td>
<b>User Name:</b> <span ><%# Eval("SystemUserName") %></span><br />
<b>Software: </b><span ><%# Eval("Software") %></span> <br />
<b>Software Key: </b><span ><%#Eval("SoftwareKey")%></span> <br />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</asp:ListView>
How to Get this type of output?,,
thanks in Advance!!
Your ASPX page :
<asp:ListView ID="Business" runat="server" OnPagePropertiesChanging="OnPagePropertiesChanging">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" >
<tr>
<td>
Username :
</td>
<td>
<%# Eval("SystemUserName")%>
</td>
</tr>
<tr>
<td>
Software :
</td>
<td>
<%# Eval("UserSoftwareDetails")%></b>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
// If you need Paging then add DataPager Ovehere
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="Business" PageSize="9">
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false"
</DataPager>
Code BEHIND :
Bind your ListView (Write Stored Procedure To Display Records)
private void BindListView()
{
// Write your Code
}
protected void Page_Load(object sender, EventArgs e)
{
BindListView();
}
and if you are doing Paging
protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
this.BindListView();
}

Changing the color of a selected row in an ASP.NET Repeater

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.

Get the id of parent listview in child listview checkbox change event

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();
}

Asp.net linkbutton in radlistview not firing events

I have a RadListView and within the listview I have an asp.net linkbutton. I want to dynamically set the linkbutton's PostBackUrl. I can achieve this if I find the linkbutton control in the listview's ItemDataBound event. But by doing this when I end up clicking on the linkbutton the listview ItemCommand event is not being fired. I need the itemCommand event to be fired so I can take the datakeyvalue of the item clicked and set it into a session variable to pass to the postbackurl page of the link button, but setting the postbackurl when the page loads causes the linkbutton not to fire any events.
<telerik:RadListView ID="lstVwWebpageList" runat="server" EnableViewState="true" ItemPlaceholderID="webpageContainer" AllowPaging="true" DataKeyNames="id" Skin="WebBlue" OnItemDataBound="lstVwWebpageList_ItemDataBound" OnPageIndexChanged="lstVwWebpageList_PageChange" Width="607px" OnItemCommand="lstVwWebpageList_ItemCommand">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:PlaceHolder ID="webpageContainer" runat="server" />
</td>
</tr>
<tr>
<td>
<telerik:RadDataPager ID="Pager" runat="server" PagedControlID="lstVwWebpageList" PageSize="50" Skin="WebBlue">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<fieldset style="float: left; width: 300px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="width: 25%;">
<b>Name:</b>
</td>
<td style="width: 75%;">
<asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 25%;">
<b>Page:</b>
</td>
<td style="width: 75%;">
<asp:LinkButton ID="pagenameLink" runat="server" OnClick="test" OnCommand="testing" CommandName="LinkClicked" Text='<%# Eval("pagename") %>' PostBackUrl='<%# "EditWebpage.aspx?name=" + Eval("name") + "&page=" + Eval("pagename") %>'></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
protected void lstVwWebpageList_ItemCommand(object sender, RadListViewCommandEventArgs e)
{
if (e.CommandName == "LinkClicked")
{
RadListViewDataItem item = (RadListViewDataItem)e.ListViewItem;
Session["linkID"] = item.DataItem;
}
}
try this
<asp:LinkButton runat="server"
ID="pagenameLink"
Text='<%# Eval("pagename") %>'
CommandName="LinkClicked"
CommandArgument='<%#Eval("name") + ", " + Eval("pagename") %>' />

Resources