By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

DataGrid onItemCommand problem

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.