3 Replies - 11519 Views - Last Post: 24 September 2009 - 08:27 PM Rate Topic: -----

#1 devsainii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 31-August 09

Datalist Link Button

Post icon  Posted 07 September 2009 - 10:47 AM

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


Is This A Good Question/Topic? 0
  • +

Replies To: Datalist Link Button

#2 babysitter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 06-August 09

Re: Datalist Link Button

Posted 10 September 2009 - 09:19 PM

do u have the SQL command in the source code?The one that uses SelectCommand="Select <something> from <tablesomething>?

please paste that here..
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 282
  • View blog
  • Posts: 1,493
  • Joined: 07-April 08

Re: Datalist Link Button

Posted 11 September 2009 - 09:03 AM

It appears to be a databound control. Can you show us the code from the aspx file that deals with the SQLDataSource?

The other Thing is that If DataLists work like DataGrids, then the onclick event of the link button will not fire if it is within the Item template.

What i would suggest is to put breakpoints in your code at the functions and events that you think are firing and see if they get hit. Also if you do find which event is hit when you click a link button then see what the sender and the event arg is and then go from there
Was This Post Helpful? 0
  • +
  • -

#4 april198474  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-September 09

Re: Datalist Link Button

Posted 24 September 2009 - 08:27 PM

1.<asp:LinkButton ID="lnk" CssClass="Name" CommandName ="lnk1" runat="server" Text='<%# Eval("name") %>' ></asp:LinkButton> should be <asp:LinkButton ID="lnk" CssClass="Name" CommandName ="lnk1" CommandArgument=<%#Eval("name")%> runat="server" Text='<%# Eval("name") %>' ></asp:LinkButton>

2. Response.Redirect("Acer.aspx"); should be
string name = Convert.Tostring(e.CommandArgument);
Response.Redirect("Acer.aspx?name="+name);

3.In the page "Acer.aspx" use "string name = request.QuerySyring["name"]" get "name" then output in the page

________________________
April
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1