473,396 Members | 2,039 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,396 software developers and data experts.

DataGrid onItemCommand problem

Hello,

<asp:DataGrid ID="dg1" AllowPaging="True" AllowSorting="True"
AlternatingItemStyle-BackColor="#ccccff"
AlternatingItemStyle-Font-Name="arial"
AlternatingItemStyle-ForeColor="#333366" CellPadding="3"
DataKeyField="empid" OnPageIndexChanged="chgpage"
OnSortCommand="sortdg" PageSize="10" PagerStyle-Mode="NumericPages"
Runat="server" PagerStyle-HorizontalAlign="Center"
OnSelectedIndexChanged="chgsel" SelectedItemStyle-BackColor="#FF0000"
AutoGenerateColumns="False" PagerStyle-BackColor="#4682b4"
PagerStyle-Font-Bold="True" PagerStyle-ForeColor="#FFFF00"
PagerStyle-Font-Name="arial,verdana" BorderColor="#4682b4"
BorderStyle="Solid" BorderWidth="2"
OnEditCommand="chkedit" OnCancelCommand="chkcancel"
OnUpdateCommand="chkupd" OnItemCommand="chkitem">
<HeaderStyle Font-Name="arial,verdana" ForeColor="#FFFF00"
BackColor="#4682b4"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="empid" HeaderText="Emp ID"
SortExpression="empid" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="empname" HeaderText="Name"
SortExpression="empname"></asp:BoundColumn>
<asp:BoundColumn DataField="passportno" HeaderText="Passport
No"></asp:BoundColumn>
<asp:BoundColumn DataField="curbasic" HeaderText="Basic"
SortExpression="curbasic"></asp:BoundColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" HeaderText="Edit Item">
<ItemStyle HorizontalAlign="Center" Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn HeaderText="Delete Item" Text="Delete"
ButtonType="PushButton" CommandName="delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
in the onitemcommand procedure,
select case ctype(e.commandsource,button).commandname
case "delete"
delete()
end select

when i press delete button, its working fine. For any other operation(sort,
page changed, edit or cancel or update) displaying an error "cast invalid at
ctype(e.commandsource,button).commandname "
Coz edit and cancel are LinkButtons and Delete is Pushbutton.

How can i validate whether e.commandsource is button or linkbutton?
And when i click Edit, datagrid columns are incorporated with textboxes
those who have been allowed for editing. Here, the textbox is displaying its
default size. How can i specify diff widths for each textbox in each column?

thanks in advance
Mar 18 '06 #1
2 3236
Hello Rajani,

Check type of the button casting to the required class. See sample below (C#)

LinkButton lnkUpdate = (LinkButton)((TableCell)e.Item.Controls[0]).Controls[0];
if (lnkUpdate != null && lnkUpdate.CommandName == "Update")
{

}

R> Hello,
R>
R> in the onitemcommand procedure,
R> select case ctype(e.commandsource,button).commandname
R> case "delete"
R> delete()
R> end select
R> when i press delete button, its working fine. For any other
R> operation(sort,
R> page changed, edit or cancel or update) displaying an error "cast
R> invalid at
R> ctype(e.commandsource,button).commandname "
R> Coz edit and cancel are LinkButtons and Delete is Pushbutton.
R> How can i validate whether e.commandsource is button or linkbutton?
R>
R> And when i click Edit, datagrid columns are incorporated with
R> textboxes those who have been allowed for editing. Here, the textbox
R> is displaying its default size. How can i specify diff widths for
R> each textbox in each column?
R>
R> thanks in advance
R>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 18 '06 #2
Hello Rajani,

Check type of the button casting to the required class. See sample below
(C#, this code gets row button)

LinkButton lnkUpdate = (LinkButton)((TableCell)e.Item.Controls[0]).Controls[0];
if (lnkUpdate != null && lnkUpdate.CommandName == "Update")
{

}

R> Hello,
R>
R> in the onitemcommand procedure,
R> select case ctype(e.commandsource,button).commandname
R> case "delete"
R> delete()
R> end select
R> when i press delete button, its working fine. For any other
R> operation(sort,
R> page changed, edit or cancel or update) displaying an error "cast
R> invalid at
R> ctype(e.commandsource,button).commandname "
R> Coz edit and cancel are LinkButtons and Delete is Pushbutton.
R> How can i validate whether e.commandsource is button or linkbutton?
R>
R> And when i click Edit, datagrid columns are incorporated with
R> textboxes those who have been allowed for editing. Here, the textbox
R> is displaying its default size. How can i specify diff widths for
R> each textbox in each column?
R>
R> thanks in advance
R>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 18 '06 #3

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

Similar topics

0
by: Ross | last post by:
Hi I am using the datagrid OnItemCommand to fire an event to remove a cell. e.Item.Cells.RemoveAt(7) e.Item.Cells.ColumnSpan = 2; Which works fine first time through but when I submit a...
1
by: Rick White | last post by:
I have an asp.net page on which I have a datagrid. The datagrid works exactly as I want up to this point: I want to have a pushbutton on the datagrid that will cause the selected row to a...
1
by: Joe | last post by:
Hi, I have form with datagrid. This is what my form tag looks like, <form runat="server"> <asp:label runat="server" id="lblMessage" /> <asp:DataGrid runat="server" id="articleList"...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
2
by: Lagwagon | last post by:
I have an Image Button inside of a Datagrid and its not firing the datagrid.itemcommand event when it is clicked. Does anyone have a link to a tutorial or a solution for this problem? For my...
0
by: LeAnne | last post by:
In my ASPX page, I populate the GRID when the user selects an item in the dropdown list. Thus, the data is fetched and the data grid DataBind() method is executed in the PostBack (i.e. IsPostBack...
0
by: Rocky | last post by:
Dear ALL, I am facing a bit problem in DATAGRID. so may be you guys can help me out. Actually on a DataGrid I am having following controls: 1) 2 DropDown Menu 2) 1 Text Box 3) 1 ADD Button 4)...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
8
by: brock wade | last post by:
I have a Datagrid that is working fine displying my records, but I'm trying to program buttons on each record line to launch another web page that shows all the details for the product: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.