DataGrid onItemCommand problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajani

    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
  • Michael Nemtsev

    #2
    Re: DataGrid onItemCommand problem

    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


    Comment

    • Michael Nemtsev

      #3
      Re: DataGrid onItemCommand problem

      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


      Comment

      Working...