AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 In Datalist, How redirect to appropirate other page by clicking link button within item templete?
Posted by Devinder Saini Dherry on  9/7/2009 1:07:55 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend

I have used datalist, within item templete I have place a link button & 2 Images.
I want when we click on link button, they redirect to other page & show me output
on which i had clicked. When i run this, they display me three different link buttons in
datalist. In database there have 3 tables for these different link buttons.
But my problem is, When either i click on button 1 or 2 or button 3, they show me always
same contents.

I want to know how we pass command arguments with itemcommand & command name.
Send me the code in C# or VB for the same.

Here is source code:---

<asp:DataList OnItemCommand="itemcommand" ID="DataList1" runat="server" DataKeyField="name" Width="600px"
DataSourceID="SqlDataSource1" RepeatColumns="3" HorizontalAlign="Center">
<ItemTemplate>

<img src="Images/<%# Eval("image") %>" alt="Laptop" />
<img src="Logos/<%# Eval("logo") %>" alt="Logo" /><br />
<asp:LinkButton ID="lnk" CssClass="Name" CommandName ="lnk1" runat="server" Text='<%# Eval("name") %>' ></asp:LinkButton><br />
Rs: <asp:Label ID="Label3" CssClass="Price" runat="server" Text='<%# Eval("price", "{0}") %>'></asp:Label>

</ItemTemplate>
</asp:DataList>


In code behind file i have used follows:--

protected void itemcommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "lnk1")
{
Response.Redirect("Acer.aspx");
}
}

Post Your Reply Post New Question

 Viewer's Reply
Change your ItemCommand event
Answered By Moderator1 on 9/15/2009 10:31:38 PM
Hi,

Everything is fine. change your itemcommand event as below

protected void itemcommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("lnk1"))
{
Response.Redirect("Acer.aspx");
}
}
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Backup and Recovery Best Practices for Microsoft SQL Server 2005
Introduction to Web Applications Development
Simply JavaScript - Free 150 Page Preview!