Can't find TableCell in DataList - asp.net

I have an ASP.Net 4.6.1 DataList on a web page with methods for both OnItemDataBound and OnItemCreated:
<asp:DataList runat="server" ID="dlAssocDetail" HorizontalAlign="Center" OnEditCommand="dlAssocDetail_EditCommand" OnUpdateCommand="dlAssocDetail_UpdateCommand"
OnCancelCommand="dlAssocDetail_CancelCommand" OnItemCommand="dlAssocDetail_ItemCommand" OnItemDataBound="dlAssocDetail_ItemDataBound" OnItemCreated="dlAssocDetail_ItemCreated">
<ItemTemplate>
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>User ID: </b><asp:Label runat="server" ID="lbEID" Text=<%# Bind("EmployeeID") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Attorney Name: </b><asp:Label runat="server" ID="lbName" Text=<%# Bind("AttorneyName") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Title: </b><asp:Label runat="server" ID="lbTitle" Text=<%# Bind("Title") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Anniversary Date: </b><asp:Label runat="server" ID="lbADate" Text=<%# Bind("AnniversaryDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Balance: </b><asp:Label runat="server" ID="lbBalance" Text=<%# Bind("Balance") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Allotment Amount: </b><asp:Label runat="server" ID="lbAAmt" Text=<%# Bind("AllotmentAmount") %> />
</asp:TableCell>
</asp:TableRow>
</asp:Table><br />
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Description: </b><asp:Label runat="server" ID="lbDesc" Text=<%# Bind("Description") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Approved: </b><asp:CheckBox runat="server" ID="cbApproved" Enabled="false" Checked=<%# Bind("Approved") %> />
<b>Rejected: </b><asp:CheckBox runat="server" ID="cbRejected" Enabled="false" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Status: </b><asp:Label runat="server" ID="lbStatus" Text=<%# Bind("OrderStatus") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Request Date: </b><asp:Label runat="server" ID="lbReqDate" Text=<%# Bind("RequestDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Order Date: </b><asp:Label runat="server" ID="lbOrderDate" Text=<%# Bind("OrderDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Received Date: </b><asp:Label runat="server" ID="lbReceivedDate" Text=<%# Bind("ReceivedDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid/Reimb Date: </b><asp:Label runat="server" ID="lbPaidDate" Text=<%# Bind("Paid_ReimbDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Total Amount: </b><asp:Label runat="server" ID="lbTotal" Text=<%# Bind("TotalAmount") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Firm: </b><asp:Label runat="server" ID="lbByFirm" Text=<%# Bind("Paid_Reimb_Amt_ByFirm") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Attorney: </b><asp:Label runat="server" ID="lbByAttorney" Text=<%# Bind("PaidAmountByAttorney") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Operating System: </b><asp:RadioButtonList runat="server" ID="rblOS" Enabled="false" SelectedValue=<%# Bind("OSID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Apple" Value="1" />
<asp:ListItem Text="Windows" Value="2" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server">
<b>Device Type: </b><asp:RadioButtonList runat="server" ID="rblDType" Enabled="false" SelectedValue=<%# Bind("DeviceTypeID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Desktop" Value="1" />
<asp:ListItem Text="Laptop" Value="2" />
<asp:ListItem Text="iPad" Value="3" />
<asp:ListItem Text="Peripheral" Value="4" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" ID="tcSpecs">
<b>Specs: </b><br /><asp:HyperLink runat="server" ID="hlSpecs" Enabled="false" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Upload: </b><asp:FileUpload runat="server" ID="fluUpload" AllowMultiple="true" Enabled="false" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Button runat="server" ID="btnEdit" CommandName="Edit" Text="Edit" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
<asp:Button runat="server" ID="btnNew" CommandName="New" Text="New" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" ColumnSpan="3" HorizontalAlign="Center">
<asp:Label runat="server" ID="lbSuccess" Font-Bold="true" Font-Names="Arial" Font-Size="X-Small" ForeColor="Red" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
<EditItemTemplate>
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>User ID: </b><asp:Label runat="server" ID="lbEID" Text=<%# Bind("EmployeeID") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Attorney Name: </b><asp:Label runat="server" ID="lbName" Text=<%# Bind("AttorneyName") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Title: </b><asp:Label runat="server" ID="lbTitle" Text=<%# Bind("Title") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Anniversary Date: </b><asp:Label runat="server" ID="lbADate" Text=<%# Bind("AnniversaryDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Balance: </b><asp:Label runat="server" ID="lbBalance" Text=<%# Bind("Balance") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Allotment Amount: </b><asp:Label runat="server" ID="lbAAmt" Text=<%# Bind("AllotmentAmount") %> />
</asp:TableCell>
</asp:TableRow>
</asp:Table><br />
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Description: </b><asp:TextBox runat="server" ID="tbDesc" Text=<%# Bind("Description") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Approved: </b><asp:CheckBox runat="server" ID="cbApproved" Checked=<%# Bind("Approved") %> />
<b>Rejected: </b><asp:CheckBox runat="server" ID="cbRejected" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Status: </b><asp:DropDownList runat="server" ID="ddlStatus" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Request Date: </b><asp:ImageButton runat="server" ID="ibReqDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbReqDate" Text=<%# Bind("RequestDate") %> />
<ajax:CalendarExtender runat="server" ID="ceReqDate" TargetControlID="tbReqDate" PopupButtonID="ibReqDate" />
<asp:ImageButton runat="server" ID="ibDelReqDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbReqDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Order Date: </b><asp:ImageButton runat="server" ID="ibOrderDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbOrderDate" Text=<%# Bind("OrderDate") %> />
<ajax:CalendarExtender runat="server" ID="ceOrderDate" TargetControlID="tbOrderDate" PopupButtonID="ibOrderDate" />
<asp:ImageButton runat="server" ID="ibDelOrderDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbOrderDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Received Date: </b><asp:ImageButton runat="server" ID="ibReceivedDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbReceivedDate" Text=<%# Bind("ReceivedDate") %> />
<ajax:CalendarExtender runat="server" ID="ceReceivedDate" TargetControlID="tbReceivedDate" PopupButtonID="ibReceivedDate" />
<asp:ImageButton runat="server" ID="ibDelReceivedDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbReceivedDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid/Reimb Date: </b><asp:ImageButton runat="server" ID="ibPaidDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbPaidDate" Text=<%# Bind("Paid_ReimbDate") %> />
<ajax:CalendarExtender runat="server" ID="cePaidDate" TargetControlID="tbPaidDate" PopupButtonID="ibPaidDate" />
<asp:ImageButton runat="server" ID="ibDelPaidDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbPaidDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Total Amount: </b><asp:TextBox runat="server" ID="tbTotal" Text=<%# Bind("TotalAmount") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbTotal"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Firm: </b><asp:TextBox runat="server" ID="tbByFirm" Text=<%# Bind("Paid_Reimb_Amt_ByFirm") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbByFirm"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Attorney: </b><asp:TextBox runat="server" ID="tbByAttorney" Text=<%# Bind("PaidAmountByAttorney") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbByAttorney"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Operating System: </b><asp:RadioButtonList runat="server" ID="rblOS" SelectedValue=<%# Bind("OSID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Apple" Value="1" />
<asp:ListItem Text="Windows" Value="2" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server">
<b>Device Type: </b><asp:RadioButtonList runat="server" ID="rblDType" SelectedValue=<%# Bind("DeviceTypeID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Desktop" Value="1" />
<asp:ListItem Text="Laptop" Value="2" />
<asp:ListItem Text="iPad" Value="3" />
<asp:ListItem Text="Peripheral" Value="4" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" ID="tcSpecs">
<b>Specs: </b><asp:HyperLink runat="server" ID="hlSpecs" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Upload: </b><asp:FileUpload runat="server" ID="fluUpload" AllowMultiple="true" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Button runat="server" ID="btnUpdate" CommandName="Update" Text="Update" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
<asp:Button runat="server" ID="btnCancel" CommandName="Cancel" Text="Cancel" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" ColumnSpan="3" HorizontalAlign="Center">
<asp:Label runat="server" ID="lbSuccess" Font-Bold="true" Font-Names="Arial" Font-Size="X-Small" ForeColor="Red" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>
</asp:DataList>
I'm trying to find a TableCell in the DataList. The ID of the TableCell is tcSpecs. When either the ItemDataBound or ItemCreated event fires, it doesn't see tcSpecs, i.e., tcSpecs remains null. Here's my code:
protected void dlAssocDetail_ItemDataBound(object sender, DataListItemEventArgs e)
{
TableCell tc = (TableCell)e.Item.FindControl("tbSpecs");
}
protected void dlAssocDetail_ItemCreated(object sender, DataListItemEventArgs e)
{
TableCell tc = (TableCell)e.Item.FindControl("tbSpecs");
}
What am I doing wrong? How do I find this TableCell?
Backing up a bit, what I'm trying to accomplish is to dynamically create a bunch of HyperLink controls on the page. I'm trying to find the TableCell so I have somewhere to put them. If anyone can suggest an alternative to using the TableCell, I'm open to that, too. Thanks much.

I figured this out. First you have to find the Table, then the TableRow, then the TableCell. So:
protected void dlAssocDetail_ItemDataBound(object sender, DataListItemEventArgs e)
{
Table ta = (Table)e.Item.FindControl("myTable");
foreach (TableRow row in ta.Rows)
foreach (TableCell cell in row.Cells)
//do something
}

Related

ASP.NET DropDownList in FormView

Been working on an ASP.NET form, and struggling with one particular part. I'm using a SqlDataSource with an Insert function that points to a stored proc, with a few input parameters. I have a FormView set up. I would like for one of the form's input fields to be a DropDownList whose options are populated from a different SqlDataSource. For reference, here is the formview:
<asp:FormView runat="server" id="FormView1" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
refund_ach:
<asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" />
<br />
refund_dba_name:
<asp:TextBox Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameTextBox" />
<br />
refund_mid:
<asp:TextBox Text='<%# Bind("mid") %>' runat="server" id="refund_midTextBox" />
<br />
refund_description:
<asp:TextBox Text='<%# Bind("description") %>' runat="server" id="refund_descriptionTextBox" />
<br />
refund_amount:
<asp:TextBox Text='<%# Bind("amount") %>' runat="server" id="refund_amountTextBox" />
<br />
refund_type:
<asp:TextBox Text='<%# Bind("type") %>' runat="server" id="refund_typeTextBox" />
<br />
<asp:LinkButton runat="server" Text="Update" CommandName="Update" id="UpdateButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Table runat="server" id="Table1">
<asp:TableRow>
<asp:TableCell>ACH?:
</asp:TableCell>
<asp:TableCell><asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>DBA Name:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>MID:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("mid") %>' runat="server" id="refund_midTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Description:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("description") %>' runat="server" id="refund_descriptionTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Amount:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("amount") %>' runat="server" id="refund_amountTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Type:
</asp:TableCell>
<asp:TableCell><asp:DropDownList DataSourceID="SqlDataSource2" SelectedValue='<%# Bind("type") %>' DataTextField="Reason" DataValueField="ID" runat="server" id="refund_typeTextBox" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" id="InsertButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
refund_ach:
<asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" Enabled="false" />
<br />
refund_dba_name:
<asp:Label Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameLabel" />
<br />
refund_mid:
<asp:Label Text='<%# Bind("mid") %>' runat="server" id="refund_midLabel" />
<br />
refund_description:
<asp:Label Text='<%# Bind("description") %>' runat="server" id="refund_descriptionLabel" />
<br />
refund_amount:
<asp:Label Text='<%# Bind("amount") %>' runat="server" id="refund_amountLabel" />
<br />
refund_type:
<asp:Label Text='<%# Bind("type") %>' runat="server" id="refund_typeLabel" />
<br />
</ItemTemplate>
</asp:FormView>
And here is the SqlDataSource:
<asp:SqlDataSource runat="server" id="SqlDataSource1" ProviderName="System.Data.SqlClient" ConnectionString="Data Source=myserver;Initial Catalog=mydatabase;Persist Security Info=True;User ID=mysvcaccount;Password=NOPE!;" SelectCommand="SELECT [refund_ach], [refund_dba_name], [refund_mid], [refund_description], [refund_amount], [refund_type] FROM [refund]" InsertCommand="EXEC usp_refund_insert #user, #ach, #dbaname, #mid, #description, #amount, #type">
<InsertParameters>
<asp:formparameter FormField="refund_achCheckBox" Name="ach" Type="Boolean" />
<asp:formparameter FormField="refund_amountTextBox" Name="amount" Type="Decimal" />
<asp:formparameter FormField="refund_dba_nameTextBox" Name="dbaname" Type="String" />
<asp:formparameter FormField="refund_descriptionTextBox" Name="description" Type="String" />
<asp:formparameter FormField="refund_midTextBox" Name="mid" Type="String" />
<asp:formparameter FormField="refund_typeTextBox" Name="type" Type="Int32" />
<asp:parameter DefaultValue="dfsdf" Name="user" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
The data populates in the DDL just fine (from another SqlDataSource). All of the desired options come up. But when submitting the form, I get an error. I removed the DDL and hard-coded a value to that parameter, and it executed fine. I spent the last couple hours scouring the internet for a solution, finding tons, trying them, and not having any luck. I'm a DBA by trade, so .NET is not my forté, but it really doesn't seem like it should be this difficult to get a DDL to work like this.
WOW. After being very frustrated, I decided to start from scratch and give it another go, just to make sure I didn't miss anything. I built everything EXACTLY the same, MINUS all of the table elements... and it worked perfectly. I added the table elements back, stopped working. Removed them again: works.
No idea why, perhaps an .NET-proficient person can explain why, but it definitely solved my problem.

How can i fire an event upon clicking the image items inside a data list?

I am a beginner in Asp.Net. I have a datalist populated with images. What i want is to know what image was clicked so that I can redirect the user to a different page as per the image clicked inside the datalist.
Here is my source:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb" Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" OnItemCommand="CatSelect" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>" onclick="cat_select" />
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
I've given comments inside the code to explain how it works.
Your HTML Designer :
<asp:datalist id="DataList1" runat="server" onitemcommand="dtlCat_ItemCommand" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server" Text='<%# Eval("FolderName") %>' />
<br />
<%--Here the "ImageID" is the Id coming from your Database--%>
<asp:ImageButton ID="ImgBtnViewInq" runat="server" ImageUrl="~/images/Viewmail.png" CommandName="View" CommandArgument='<%# Eval("ImageID") %>' ToolTip="View" />
<%--You can do the same from your link button here too the "ImageID" is the Id coming from your Database--%>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" CommandArgument='<%# Eval("ImageID") %>' ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:datalist>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
C# Code Behind :
protected void dtlCat_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "View")
{
// Here "i" will get the imageid(CommandArgument='<%# Eval("ImageID") %>') that was given inside the image button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
if (e.CommandName == "show")
{
// Here "i" will get the imageid (CommandArgument='<%# Eval("ImageID") %>') that was given inside the Link button tag
int i = Convert.ToInt32(e.CommandArgument);
Response.Redirect("YourPage.aspx?clickedimgID=" + i);
}
}
Hope that helps
Try this
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MediaCenter.aspx.vb"
Inherits="Default2" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.11.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Categories<br />
<br />
<br />
<asp:DataList ID="dtlCat" runat="server" DataKeyField="FolderId"
DataSourceID="SqlDataSource1" Height="96px" HorizontalAlign="Center"
RepeatDirection="Horizontal" Width="257px" BorderStyle="Solid"
GridLines="Horizontal" BackColor="White" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" Caption="Album Gallery"
ItemStyle-HorizontalAlign="Center" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:Label ID="FolderNameLabel" runat="server"
Text='<%# Eval("FolderName") %>' />
<br />
<img src="<%# ResolveUrl(String.Format("~/img/apple-touch-icon-114x114.png", Container.DataItem)) %>"/>
<asp:LinkButton ID="lnkBtn" runat="server" CommandName="show" ></asp:LinkButton>
<asp:Label ID="UrlLabel" runat="server" Text='<%# Eval("Url") %>' />
<br />
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AbcWebConnStr %>"
SelectCommand="SELECT * FROM [Folder]"></asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Hope this may helps you. Let me Know if it helps you.

How do i get asp:Panel Default Button to fire button click event?

I have three asp net text boxes that will contain search criteria for searching a table. I would like the search to work like Google. When the enter key is pressed to have the click event on the "Enter" button fire. The click event never fires. What can I do to get it to fire?
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebCategoryGenerateEdit.ascx.cs"
Inherits="EPPA.Controls.WebCategoryGenerateEdit" ClientIDMode="Static" %>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
// debugger;
function pageLoad() {
var gvCategoryMessage = $("#<%=GVCategoryMessage.ClientID %>").html
if (gvCategoryMessage.length != 0) {
$("#<%=GVParentCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
$("#<%=GVCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
}
}
</script>
<asp:ScriptManager runat="server" />
<asp:MultiView ID="Multiview1" runat="server" ActiveViewIndex="0">
<asp:View ID="SearchView" runat="server">
<asp:Table ID="TableSV1" runat="server">
<asp:TableRow ID="TableRowSV1" runat="server">
<asp:TableCell ID="TableCellSV1" runat="server">
<asp:Label ID="LabelSV1" runat="server" SkinID="SearchTextLabel"
Text="CB or CJ" CssClass="searchTextLabel_Division"/>
</asp:TableCell>
<asp:TableCell ID="TableCellSV2" runat="server">
<asp:Label ID="LabelSV2" runat="server"
SkinID="SearchTextLabel" Text="Parent Category Link Title"
CssClass="searchTextLabel_ParentCategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV3" runat="server">
<asp:Label ID="LabelSV3" runat="server"
SkinID="SearchTextLabel"
Text="Category Link Title" CssClass="searchTextLabel_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV4" runat="server">
<asp:Label ID="Label1" runat="server"
SkinID="SearchTextLabel"
Text="Category ID" CssClass="searchTextLabel_CategoryID" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="SVTableRowSV2" runat="server">
<asp:TableCell ID="TableCellSV5" runat="server">
<asp:DropDownList ID="SVDivisionDDL" runat="server"
OnSelectedIndexChanged="SVDivisionDDL_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="CB">CB</asp:ListItem>
<asp:ListItem Value="CJ">CJ</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
<asp:TableCell ID="TableCellSV6" runat="server" >
<asp:panel ID="SVPCLTContainer" runat="server"
DefaultButton="SV6EnterButton">
<asp:TextBox ID="SVParentCategoryLinkTitle" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_ParentCategoryLink" />
<asp:Button ID="SV6EnterButton" runat="server" Visible="false"
Text="Enter" OnClick="EnterKeyPressed_Click" />
</asp:panel>
</asp:TableCell>
<asp:TableCell ID="TableCellSV7" runat="server" >
<asp:TextBox ID="SVCategoryLinkTitle"
runat="server" SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV8" runat="server" >
<asp:TextBox ID="SVCategoryID" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryID" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="SVGenNewButton" runat="server" Text="Generate New Category ID"
OnClick="SVGenerateNewButton_Click" />
<asp:Button ID="SVDeleteButton" runat="server" Text="Delete Checked items"
OnClick="SVDeleteButton_Click" />
<div style="width:618px; overflow-x:no-display; overflow-y:auto; max-height:392px;
padding-top:2px; ">
<asp:GridView ID="gvWebCategoryID" runat="server" AutoGenerateColumns="False"
SkinID="gridViewSkin" OnRowDeleting="gvWebCategoryID_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="SVgridViewEditButton" runat="server"
OnClick="gvWeCategoryIDEditButton_Click" Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Division" HeaderText="CB or CJ"
Visible="true" />
<asp:BoundField DataField="ParentCategoryLinkTitle" HeaderText="Parent
Category Link Title" />
<asp:BoundField DataField="CategoryLinkTitle" HeaderText="Category
Link Title" />
<asp:BoundField DataField="CategoryID" HeaderText="Category ID" />
<asp:TemplateField HeaderText="Error Message" Visible="false" >
<ItemTemplate>
<asp:Label ID="ErrorMessage" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:View>
</asp:MultiView>
and here is the behind code method:
protected void EnterKeyPressed_Click(object sender, EventArgs e)
{
ReloadData();
this.Multiview1.ActiveViewIndex = 0;
}
At a quick glance, have you tried removing the return false here:
$("#<%=SVParentCategoryLinkTitle.ClientID %>").keydown(function (e) {
if (e.which == 13) {
__doPostBack("#<%=EnterKeyPressed.UniqueID %>", "");
return false;
}
})
check out this question and answer, if it helps: Default button not working in asp.net panel
the DefaultButton is used to capture the Enter key press if the focus is already inside the panel, for example you must have moved the focus to an input field like the text boxes inside the panel. if the focus is not there it won't work.

Button refuses to work

I have a standard button which should call a method but it just refuses to work and I can't figure out why.
ASP code:
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" />
Code behind:
protected void UploadButton_Click(object sender, EventArgs e)
{
PasswordLabel.Visible = true;
PasswordLabel.Text = "TEST Before";
Image_Inserting(this);
PasswordLabel.Text = "TEST After";
}
I just added the textbox methods to test it but it doesn't seem to be posting back (even when I remove Image_Inserting call). All other buttons work fine so I don't know why this one won't work.
EDIT: Whole page- Button code towards the bottom
<%# Page Title="" Language="C#" MasterPageFile="~/Standardmaster.Master" AutoEventWireup="true" CodeBehind="VendorAccount.aspx.cs" Inherits="PetShopParadise.Vendor_Pages.VendorAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style10
{
color: #FF0000;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
<h2>Account Details</h2>
<div id="RegistrationDiv">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone Number:
<asp:Label ID="Phone_NumberLabel" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:Button ID="Button3" runat="server" Text="Edit Details" CommandName="Edit" />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
SelectCommand="SELECT [Name], [Address], [Phone_Number] FROM [Vendors] WHERE ([VendorID] = #VendorID)">
<SelectParameters>
<asp:SessionParameter Name="VendorID" SessionField="ID" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Table ID="Table1" runat="server" style="text-align:left;">
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell7" runat="server">Password</asp:TableCell><asp:TableCell ID="TableCell8" runat="server">
<asp:TextBox ID="PasswordBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator5"
runat="server"
ControlToValidate="PasswordBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please enter a password." />
</asp:TableCell></asp:TableRow><asp:TableRow ID="TableRow5" runat="server">
<asp:TableCell ID="TableCell9" runat="server">Re-Enter Password</asp:TableCell><asp:TableCell ID="TableCell10" runat="server">
<asp:TextBox ID="PasswordCheckBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator6"
runat="server"
ControlToValidate="PasswordCheckBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please re-enter your password." />
</asp:TableCell></asp:TableRow></asp:Table><asp:Label
ID="PasswordLabel" runat="server" Text="Password" CssClass="style10"></asp:Label><br />
<asp:Button ID="PasswordButton"
runat="server" Text="Update Password" onclick="PasswordButton_Click" /><br />
<asp:SqlDataSource
ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
onselecting="SqlDataSource2_Selecting" SelectCommand="SELECT * FROM Vendors"
UpdateCommand="UPDATE [Vendors] SET [Password]=#passwordhash WHERE ([VendorID] = #VendorID)" OnUpdating="Parameters_Updating">
<UpdateParameters>
<asp:Parameter Name="Password" />
<asp:SessionParameter name="VendorID" sessionfield="ID" />
</UpdateParameters>
</asp:SqlDataSource>
<br /><asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" /></div></asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="bannerContent" runat="server">
</asp:Content>
My guess is that it is causing other (possibly hidden) validation to run. Make sure to set CausesValidation to false.
quote :
*I just added the textbox methods *
I guess our trying to update a Password textBox which you can't.
only by :
PasswordLabel .Attributes["value"] = "aaa";

prepopulate textbox with variable, asp.net

I'd like to prepopulate my textfield with the following variable:
<%=Membership.GetUser().Email%>
... so that users can submit their email address to my table without having to type it in.
Here is my code:
<form id="form1" runat="server">
<div>
<!-- This is the code for the form. There is a Text Box to collect the first name,
last name and email address. All fields are required and I am validating that the
email address is a valid format. -->
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>First Name: <asp:TextBox ID="txtFirstName"
runat="server" Width="60" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ErrorMessage="Enter First Name" Text="*" ControlToValidate="txtFirstName"
runat="server" />
</asp:TableCell>
<asp:TableCell>Last Name: <asp:TextBox ID="txtLastName" runat="server" Width="60" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtLastName" ErrorMessage="Enter Last Name" Text="*" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Email: <asp:TextBox ID="txtEmail" runat="server" Width="80" />
<asp:RequiredFieldValidator ID="emailRequired"
runat="server" ControlToValidate="txtEmail" ErrorMessage="Email Needs Information"
Text="*"/>
<asp:RegularExpressionValidator ID="emailexpression"
runat="server" ControlToValidate="txtEmail" ValidationExpression=".*#.*\..*"
ErrorMessage="Invalide Email Address" Text="*" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="true"
ShowMessageBox="true" runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button ID="btnSubmit" runat="server" OnClick="addMember"
CausesValidation="true" Height="30" Width="100" Text="Add Me" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblDuplicate" runat="server" Text=""></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
How can I accomplish this?
Pop it in the page load event in the code-behind?
if (!Page.IsPostBack)
{
txtEmail.Text = Membership.GetUser().Email;
}

Resources