Hi all,
I am trying to have a linkbutton control with the commandname property set.
However, when I invoke it, the CommandArgument property ends up coming to be
blank. However, if I click on the buttonfield control i get back the
rowindex in CommandArgument. Why is that? How do I get my custom linkbutton
to work?
public void GridView_Command(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "EditSelect":
Response.Write(e.CommandArgument);
Response.End();
GridView_Edit(Convert.ToInt32(e.CommandArgument));
break;
}
}
<asp:ButtonField ButtonType="Link" CommandName="EditSelect" HeaderText="ID"
Text="Edit" />
<asp:TemplateField HeaderText="ID" HeaderStyle-HorizontalAlign="left"
ItemStyle-HorizontalAlign="left">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" Text='<%#Eval("feeid") %>'
CommandName="EditSelect" />
</ItemTemplate>
</asp:TemplateField>
TIA! 3 3367
Thanks for Suresh's input.
Hi Param,
As for the ASP.NET GridView control, it will use the CommandArgument
property of Command button(Button or LinkButton) to hold the RowIndex
parameter. The built-in CommandField/ButtonField will use the following
code to assign the rowindex at Button's creation time:
===reflector diassembled code===
control1.Text = this.Text;
control1.CommandName = this.CommandName;
control1.CommandArgument =
rowIndex.ToString(CultureInfo.InvariantCulture);
====================
Therefore, if you have a custom template field that will add a button
control to trigger a GridView event, you can manually set the current
rowindex into the button's "CommandArgument" field. e.g.
======in aspx template==========
<asp:GridView ID="GridView1" .............. AllowPaging="True" PageSize="4">
<Columns>
..................
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandName="Select" CommandArgument="<%# Container.DisplayIndex %>">My
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
...........
=============================
or you can also use RowDataBound event to set the commandargument. e.g.
======in RowDataBound event==========
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btn = e.Row.FindControl("btn1") as LinkButton;
if (btn != null)
{
btn.CommandArgument =
e.Row.RowIndex.ToString(CultureInfo.InvariantCultu re);
}
}
}
=====================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks Suresh. that worked.
"Suresh" <Su****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
>I believe using the CommandArgument to determine the row index only works
when you use the command field in a gridview.
Not sure if row index is what you are after in the CommandArgument??
If it is try the following:
(FYI you can bind any data item value to the commandargument property as
well)
asp:LinkButton ID="btnedit" runat="server" Text='<%#Eval("feeid") %>'
CommandName="EditSelect" CommandArgument="<%# Container.DataItemIndex %>"
/>
HTH,
Suresh.
"pa***@community.nospam" wrote:
>Hi all,
I am trying to have a linkbutton control with the commandname property set. However, when I invoke it, the CommandArgument property ends up coming to be blank. However, if I click on the buttonfield control i get back the rowindex in CommandArgument. Why is that? How do I get my custom linkbutton to work?
public void GridView_Command(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "EditSelect":
Response.Write(e.CommandArgument);
Response.End();
GridView_Edit(Convert.ToInt32(e.CommandArgument)) ;
break;
}
}
<asp:ButtonField ButtonType="Link" CommandName="EditSelect" HeaderText="ID" Text="Edit" />
<asp:TemplateField HeaderText="ID" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" Text='<%#Eval("feeid") %>' CommandName="EditSelect" />
</ItemTemplate>
</asp:TemplateField> TIA!
Hi Param,
DataItemIndex refer to the index of current databound item in the
datasource. The value may differ from actual GridView item index when you
using paging. the DisplayIndex matchs the actual GridView itemindex no
matter you use paging or not.
<asp:LinkButton ID="LinkButton1" runat="server"
CommandName="Select" CommandArgument="<%# Container.DisplayIndex %>">My
Select</asp:LinkButton>
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Parter |
last post by:
I have a GridView control which is bound to a Stored Procedure (SP) using a
SQLDataSource. The problem I'm having is that the SP returns 4 known columns
and x amount of unknown columns.
I can...
|
by: Krish |
last post by:
Hello Gurus,
I have Master GridView & Detail1 Gridview & Detail2 Gridview controls. On
"select" master grid , No. 1detail grid shows data, On
"Select" No. 1. detail grid, No.2 detail grid shows...
|
by: CK |
last post by:
Hi All,
I have a gridview that contains a column that has a repeater inside it. My
intent is to put every comment for an album into the repeater in the
comments column. I am using a SQLDataSource...
|
by: rodchar |
last post by:
hey all,
i have a simple gridView that contains 2 columns with a dropdownlist in each
column. for instance, when a user selects a product category from ddl1 then
ddl2 will filter the products...
|
by: trint |
last post by:
I hope I can explain this clearly enough to get help.
I have three gridviews that need to work from each other to
display like a java verticle menu (just in the way it appears).
GridView1 is...
|
by: New2ASP |
last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer.
Here's the structure of my Gridview
Column 1 : Checkbox with SelectAll...
|
by: sharonrao123 |
last post by:
hello all,
I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
|
by: =?Utf-8?B?U2FuZHBvaW50R3V5?= |
last post by:
I have a gridview that is displaying product information with links to edit
pages.
The customer now wants to perform mass deletes on the grid page, such as by
adding checkboxes on each row - and...
|
by: nguyenlh |
last post by:
I perform a module in dotnetnuke
module perform insert , update and delete
and display on gridview
I have inserted and delete and update but
when i tao SqlDatasource give gridview then...
|
by: johnix |
last post by:
i am very newbie of asp.net..
i dont know how to get the value for my update event or display ii, from the textbox in gridview.
code in my html
<form id="form1" runat="server">
<div>...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |