473,698 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid onItemCommand problem

Hello,

<asp:DataGrid ID="dg1" AllowPaging="Tr ue" AllowSorting="T rue"
AlternatingItem Style-BackColor="#ccc cff"
AlternatingItem Style-Font-Name="arial"
AlternatingItem Style-ForeColor="#333 366" CellPadding="3"
DataKeyField="e mpid" OnPageIndexChan ged="chgpage"
OnSortCommand=" sortdg" PageSize="10" PagerStyle-Mode="NumericPa ges"
Runat="server" PagerStyle-HorizontalAlign ="Center"
OnSelectedIndex Changed="chgsel " SelectedItemSty le-BackColor="#FF0 000"
AutoGenerateCol umns="False" PagerStyle-BackColor="#468 2b4"
PagerStyle-Font-Bold="True" PagerStyle-ForeColor="#FFF F00"
PagerStyle-Font-Name="arial,ver dana" BorderColor="#4 682b4"
BorderStyle="So lid" BorderWidth="2"
OnEditCommand=" chkedit" OnCancelCommand ="chkcancel"
OnUpdateCommand ="chkupd" OnItemCommand=" chkitem">
<HeaderStyle Font-Name="arial,ver dana" ForeColor="#FFF F00"
BackColor="#468 2b4"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="empi d" HeaderText="Emp ID"
SortExpression= "empid" ReadOnly="True" ></asp:BoundColumn >
<asp:BoundColum n DataField="empn ame" HeaderText="Nam e"
SortExpression= "empname"></asp:BoundColumn >
<asp:BoundColum n DataField="pass portno" HeaderText="Pas sport
No"></asp:BoundColumn >
<asp:BoundColum n DataField="curb asic" HeaderText="Bas ic"
SortExpression= "curbasic"> </asp:BoundColumn >
<asp:EditComman dColumn EditText="Edit" CancelText="Can cel"
UpdateText="Upd ate" HeaderText="Edi t Item">
<ItemStyle HorizontalAlign ="Center" Wrap="False"></ItemStyle>
</asp:EditCommand Column>
<asp:ButtonColu mn HeaderText="Del ete Item" Text="Delete"
ButtonType="Pus hButton" CommandName="de lete"></asp:ButtonColum n>
</Columns>
</asp:DataGrid>
in the onitemcommand procedure,
select case ctype(e.command source,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.command source,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 3244
Hello Rajani,

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

LinkButton lnkUpdate = (LinkButton)((T ableCell)e.Item .Controls[0]).Controls[0];
if (lnkUpdate != null && lnkUpdate.Comma ndName == "Update")
{

}

R> Hello,
R>
R> in the onitemcommand procedure,
R> select case ctype(e.command source,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.command source,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)((T ableCell)e.Item .Controls[0]).Controls[0];
if (lnkUpdate != null && lnkUpdate.Comma ndName == "Update")
{

}

R> Hello,
R>
R> in the onitemcommand procedure,
R> select case ctype(e.command source,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.command source,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
1156
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 button that resides in a user control with a search box also on the page the
1
1825
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 different table. There are many examples of this, but I can't seem to get the OnItemCommand handler to fire. The page is called DraftHitters.aspx and has the C# code in DraftHitters.aspx.cs. Everything _else_ works great. Here are some snippets:
1
1320
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" DataKeyField="FullName" OnItemDataBound="articleList_ItemDataBound" OnEditCommand = "articleList_Edit"
4
2129
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 Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
2
1678
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 datagrid I do have the OnItemCommand propert set. <asp: Datagrid id="DataGrid1" runat="server" OnItemCommand="gStarted"> In the code the function is:
0
1130
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 = TRUE on the server side). At this time the data grid has some information and is now displayed. How ever, the OnItemCommand that I've specified in the data grid doesn't seem to get executed at ALL. I.e. i've placed a simple button control...
0
1226
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) 1 Remove Button So these all controls are in 1 row and looks like:
0
2084
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
8
1254
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: <asp:datagrid id="dgProducts" runat="server"> <asp:ButtonColumn Text="Details" CommandName="Details" ButtonType="PushButton"></asp:ButtonColumn> </asp:datagrid>
0
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8858
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5859
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.