Datagrid OnDeleteCommand

Discussion in 'ASP .Net Datagrid Control' started by CalSun, Jun 29, 2005.

  1. CalSun

    CalSun Guest

    I have a datagrid with a templatecolumn where I have the Delete linkbuttons.
    As I click on the Del linkbutton, it calls the delete_func. However, I can't
    get the value of the cell to use it as a key in sql_delete statement.

    Here is my delete buttons
    <asp:TemplateColumn HeaderText="Del/Add" ItemStyle-HorizontalAlign=Center
    FooterStyle-HorizontalAlign=Center>
    <ItemTemplate>
    <asp:LinkButton id="btndelete" Runat=server Text="Del"
    CommandName="cmdDelete" ForeColor=red>Del</asp:LinkButton>
    </ItemTemplate>
    <FooterTemplate>
    <asp:LinkButton id="btnAdd" runat="server" CommandName="cmdAddRow"
    ForeColor=navy>Add</asp:LinkButton>
    </FooterTemplate>
    </asp:TemplateColumn>

    In the delete function:
    public void grid_DelAdd(Object sender, DataGridCommandEventArgs e)
    {
    if (e.CommandName == "cmdDelete")
    {
    e.Item.ItemIndex ---> this reflect the correct index on the
    current datagrid
    string = (string) e.Item.Cells[2].Text; ---> return an
    empty string, even the field (cell) is with some data
    ...
    }

    Thanks in advance.

    --Cal
     
    CalSun, Jun 29, 2005
    #1
    1. Advertising

  2. CalSun

    Elton Wang Guest

    Hi Cal,

    Could you show your whole datagrid html code?

    Elton Wang

    "CalSun" <> wrote in message
    news:%23%...
    > I have a datagrid with a templatecolumn where I have the Delete

    linkbuttons.
    > As I click on the Del linkbutton, it calls the delete_func. However, I

    can't
    > get the value of the cell to use it as a key in sql_delete statement.
    >
    > Here is my delete buttons
    > <asp:TemplateColumn HeaderText="Del/Add" ItemStyle-HorizontalAlign=Center
    > FooterStyle-HorizontalAlign=Center>
    > <ItemTemplate>
    > <asp:LinkButton id="btndelete" Runat=server Text="Del"
    > CommandName="cmdDelete" ForeColor=red>Del</asp:LinkButton>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:LinkButton id="btnAdd" runat="server" CommandName="cmdAddRow"
    > ForeColor=navy>Add</asp:LinkButton>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    >
    > In the delete function:
    > public void grid_DelAdd(Object sender, DataGridCommandEventArgs e)
    > {
    > if (e.CommandName == "cmdDelete")
    > {
    > e.Item.ItemIndex ---> this reflect the correct index on the
    > current datagrid
    > string = (string) e.Item.Cells[2].Text; ---> return an
    > empty string, even the field (cell) is with some data
    > ...
    > }
    >
    > Thanks in advance.
    >
    > --Cal
    >
    >
     
    Elton Wang, Jun 30, 2005
    #2
    1. Advertising

  3. CalSun

    CalSun Guest

    Thanks Wang. I figured out my problem. I used controlfinder and casted the
    control accordingly.

    --cal


    "Elton Wang" <> wrote in message
    news:%...
    > Hi Cal,
    >
    > Could you show your whole datagrid html code?
    >
    > Elton Wang
    >
    > "CalSun" <> wrote in message
    > news:%23%...
    >> I have a datagrid with a templatecolumn where I have the Delete

    > linkbuttons.
    >> As I click on the Del linkbutton, it calls the delete_func. However, I

    > can't
    >> get the value of the cell to use it as a key in sql_delete statement.
    >>
    >> Here is my delete buttons
    >> <asp:TemplateColumn HeaderText="Del/Add" ItemStyle-HorizontalAlign=Center
    >> FooterStyle-HorizontalAlign=Center>
    >> <ItemTemplate>
    >> <asp:LinkButton id="btndelete" Runat=server Text="Del"
    >> CommandName="cmdDelete" ForeColor=red>Del</asp:LinkButton>
    >> </ItemTemplate>
    >> <FooterTemplate>
    >> <asp:LinkButton id="btnAdd" runat="server" CommandName="cmdAddRow"
    >> ForeColor=navy>Add</asp:LinkButton>
    >> </FooterTemplate>
    >> </asp:TemplateColumn>
    >>
    >> In the delete function:
    >> public void grid_DelAdd(Object sender, DataGridCommandEventArgs e)
    >> {
    >> if (e.CommandName == "cmdDelete")
    >> {
    >> e.Item.ItemIndex ---> this reflect the correct index on the
    >> current datagrid
    >> string = (string) e.Item.Cells[2].Text; ---> return an
    >> empty string, even the field (cell) is with some data
    >> ...
    >> }
    >>
    >> Thanks in advance.
    >>
    >> --Cal
    >>
    >>

    >
    >
     
    CalSun, Jun 30, 2005
    #3
  4. CalSun

    Elton Wang Guest

    That's right. Unless you use BoundColumn, you should use e.Item.FindControl
    to locate requied control.

    "CalSun" <> wrote in message
    news:...
    > Thanks Wang. I figured out my problem. I used controlfinder and casted the
    > control accordingly.
    >
    > --cal
    >
    >
    > "Elton Wang" <> wrote in message
    > news:%...
    > > Hi Cal,
    > >
    > > Could you show your whole datagrid html code?
    > >
    > > Elton Wang
    > >
    > > "CalSun" <> wrote in message
    > > news:%23%...
    > >> I have a datagrid with a templatecolumn where I have the Delete

    > > linkbuttons.
    > >> As I click on the Del linkbutton, it calls the delete_func. However, I

    > > can't
    > >> get the value of the cell to use it as a key in sql_delete statement.
    > >>
    > >> Here is my delete buttons
    > >> <asp:TemplateColumn HeaderText="Del/Add"

    ItemStyle-HorizontalAlign=Center
    > >> FooterStyle-HorizontalAlign=Center>
    > >> <ItemTemplate>
    > >> <asp:LinkButton id="btndelete" Runat=server Text="Del"
    > >> CommandName="cmdDelete" ForeColor=red>Del</asp:LinkButton>
    > >> </ItemTemplate>
    > >> <FooterTemplate>
    > >> <asp:LinkButton id="btnAdd" runat="server" CommandName="cmdAddRow"
    > >> ForeColor=navy>Add</asp:LinkButton>
    > >> </FooterTemplate>
    > >> </asp:TemplateColumn>
    > >>
    > >> In the delete function:
    > >> public void grid_DelAdd(Object sender, DataGridCommandEventArgs e)
    > >> {
    > >> if (e.CommandName == "cmdDelete")
    > >> {
    > >> e.Item.ItemIndex ---> this reflect the correct index on

    the
    > >> current datagrid
    > >> string = (string) e.Item.Cells[2].Text; ---> return

    an
    > >> empty string, even the field (cell) is with some data
    > >> ...
    > >> }
    > >>
    > >> Thanks in advance.
    > >>
    > >> --Cal
    > >>
    > >>

    > >
    > >

    >
    >
     
    Elton Wang, Jun 30, 2005
    #4
  5. CalSun

    CalSun Guest

    the down side is taking time to name all the controls.
    --Cal
    "Elton Wang" <> wrote in message
    news:OJG0$...
    > That's right. Unless you use BoundColumn, you should use
    > e.Item.FindControl
    > to locate requied control.
    >
    > "CalSun" <> wrote in message
    > news:...
    >> Thanks Wang. I figured out my problem. I used controlfinder and casted
    >> the
    >> control accordingly.
    >>
    >> --cal
    >>
    >>
    >> "Elton Wang" <> wrote in message
    >> news:%...
    >> > Hi Cal,
    >> >
    >> > Could you show your whole datagrid html code?
    >> >
    >> > Elton Wang
    >> >
    >> > "CalSun" <> wrote in message
    >> > news:%23%...
    >> >> I have a datagrid with a templatecolumn where I have the Delete
    >> > linkbuttons.
    >> >> As I click on the Del linkbutton, it calls the delete_func. However, I
    >> > can't
    >> >> get the value of the cell to use it as a key in sql_delete statement.
    >> >>
    >> >> Here is my delete buttons
    >> >> <asp:TemplateColumn HeaderText="Del/Add"

    > ItemStyle-HorizontalAlign=Center
    >> >> FooterStyle-HorizontalAlign=Center>
    >> >> <ItemTemplate>
    >> >> <asp:LinkButton id="btndelete" Runat=server Text="Del"
    >> >> CommandName="cmdDelete" ForeColor=red>Del</asp:LinkButton>
    >> >> </ItemTemplate>
    >> >> <FooterTemplate>
    >> >> <asp:LinkButton id="btnAdd" runat="server" CommandName="cmdAddRow"
    >> >> ForeColor=navy>Add</asp:LinkButton>
    >> >> </FooterTemplate>
    >> >> </asp:TemplateColumn>
    >> >>
    >> >> In the delete function:
    >> >> public void grid_DelAdd(Object sender, DataGridCommandEventArgs e)
    >> >> {
    >> >> if (e.CommandName == "cmdDelete")
    >> >> {
    >> >> e.Item.ItemIndex ---> this reflect the correct index on

    > the
    >> >> current datagrid
    >> >> string = (string) e.Item.Cells[2].Text; ---> return

    > an
    >> >> empty string, even the field (cell) is with some data
    >> >> ...
    >> >> }
    >> >>
    >> >> Thanks in advance.
    >> >>
    >> >> --Cal
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    CalSun, Jun 30, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Cox, MCSD

    OnDeleteCommand Not Refreshing Page

    Terry Cox, MCSD, Oct 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    375
    Terry Cox, MCSD
    Oct 24, 2003
  2. Defty

    DataGrid OnDeleteCommand Problem

    Defty, May 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,180
    Defty
    May 28, 2004
  3. Iain

    OndeleteCommand does not fire

    Iain, Feb 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    415
  4. RN1

    DataGrid OnDeleteCommand

    RN1, Mar 7, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    464
  5. Andreas Klemt
    Replies:
    0
    Views:
    319
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page