473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Get row number of Linkbutton

I have a DataGrid:

<asp:datagrid id="articleList" runat="server"
OnDeleteCommand="articleList_DeleteFile"
OnItemDataBound="articleList_ItemDataBound"
DataKeyField="FullName" AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name"></asp:HyperLinkColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad"
OnClick="DownLoad_Click" Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

I need to get the path and filename of the row selected which is in the
DataKeys fields.

In my Delete button, I find it like so:

public void articleList_DeleteFile(Object sender, DataGridCommandEventArgs
e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

But for the link button I can't use e.Item.ItemIndex to find the row number,
so the following doesn't work.

public void DownLoad_Click(Object sender, EventArgs e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

I get an error:

'System.EventArgs' does not contain a definition for 'Item'

How do I get the Row number so I can do something like:

string fileName = (string)articleList.DataKeys[ROWNUMBER];

Thanks,

Tom
Sep 22 '06 #1
2 2557
Hi,
You can set the CommandName property of the link button to "Download",
remove the OnCilck handler from the LinkButton and use the DataGridCommand
event handler as follows

public void articleList_ItemCommand(Object sender, DataGridCommandEventArgs
e)
{
if (e.CommandName=="Delete")
{
//delete
}
if (e.CommandName=="Download")
{
//download
}
}
Regards,
Mohamed Mosalem

"tshad" <ts**********@ftsolutions.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
>I have a DataGrid:

<asp:datagrid id="articleList" runat="server"
OnDeleteCommand="articleList_DeleteFile"
OnItemDataBound="articleList_ItemDataBound"
DataKeyField="FullName" AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name"></asp:HyperLinkColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad"
OnClick="DownLoad_Click" Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

I need to get the path and filename of the row selected which is in the
DataKeys fields.

In my Delete button, I find it like so:

public void articleList_DeleteFile(Object sender, DataGridCommandEventArgs
e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

But for the link button I can't use e.Item.ItemIndex to find the row
number, so the following doesn't work.

public void DownLoad_Click(Object sender, EventArgs e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

I get an error:

'System.EventArgs' does not contain a definition for 'Item'

How do I get the Row number so I can do something like:

string fileName = (string)articleList.DataKeys[ROWNUMBER];

Thanks,

Tom


Sep 23 '06 #2
That works.

Thanks,

Tom
"Mohamed Mosalem" <mo*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,
You can set the CommandName property of the link button to "Download",
remove the OnCilck handler from the LinkButton and use the DataGridCommand
event handler as follows

public void articleList_ItemCommand(Object sender,
DataGridCommandEventArgs e)
{
if (e.CommandName=="Delete")
{
//delete
}
if (e.CommandName=="Download")
{
//download
}
}
Regards,
Mohamed Mosalem

"tshad" <ts**********@ftsolutions.comwrote in message
news:eI**************@TK2MSFTNGP03.phx.gbl...
>>I have a DataGrid:

<asp:datagrid id="articleList" runat="server"
OnDeleteCommand="articleList_DeleteFile"
OnItemDataBound="articleList_ItemDataBound"
DataKeyField="FullName" AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name"></asp:HyperLinkColumn>
<asp:TemplateColumn HeaderText="DownLoad">
<ItemTemplate>
<asp:LinkButton id="DownLoad" Text="DownLoad"
OnClick="DownLoad_Click" Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

I need to get the path and filename of the row selected which is in the
DataKeys fields.

In my Delete button, I find it like so:

public void articleList_DeleteFile(Object sender,
DataGridCommandEventArgs e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

But for the link button I can't use e.Item.ItemIndex to find the row
number, so the following doesn't work.

public void DownLoad_Click(Object sender, EventArgs e)
{
//First, get the filename to delete
string fileName = (string)articleList.DataKeys[e.Item.ItemIndex];

I get an error:

'System.EventArgs' does not contain a definition for 'Item'

How do I get the Row number so I can do something like:

string fileName = (string)articleList.DataKeys[ROWNUMBER];

Thanks,

Tom



Sep 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the...
2
by: News | last post by:
Hi, I need help with datalist and linkbutton. I need a LinkButton to display in datalist if datafield "is_measure_customchecklist" in a db table set to true. Here is the code (in parts): ...
3
by: MRW | last post by:
I have a simple linkbutton and a function when it's clicked. It works perfectly in a regular .aspx page. However, when I place it inside the ContentPlaceHolder, it no longer works. It does...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
3
by: rn5a | last post by:
Consider the following code which creates LinkButtons dynamically: For i = 1 to 5 lnkBut = New LinkButton lnkBut.ID = "lnkBut" & i lnkBut.Text = i.ToString & " " lnkBut.CommandName = i...
0
by: OceanBreeze | last post by:
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The...
3
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I have two sets of search criteria on my page. They are placed inside two DIV tags made visible/hidden by a client script. In each DIV tag I have a LinkButton that performs the search from each...
0
by: HillBilly | last post by:
MasterPages again. Three LinkButtons are being used as styled tabs in the content page that will load a different ListView when a tab is selected: TabA, TabB or TabC. The LinkButtons are declared...
5
by: Peter Larsen [CPH] | last post by:
Hi, The following sample shows a LinkButton in the HeaderTemplate of a Repeater control. The problem is that i'm not able to access the linkbutton in code (in the cs file) as long as the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.