Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid OnDeleteCommand

Reply
Thread Tools

Datagrid OnDeleteCommand

 
 
CalSun
Guest
Posts: n/a
 
      06-29-2005
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


 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      06-30-2005
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
>
>



 
Reply With Quote
 
 
 
 
CalSun
Guest
Posts: n/a
 
      06-30-2005
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
>>
>>

>
>



 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      06-30-2005
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
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
CalSun
Guest
Posts: n/a
 
      06-30-2005
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
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid OnDeleteCommand RN1 ASP .Net 0 03-07-2008 07:59 PM
OndeleteCommand does not fire Iain ASP .Net 1 02-27-2007 03:26 PM
DataGrid OnDeleteCommand Problem Defty ASP .Net 2 05-28-2004 09:43 AM
OnDeleteCommand Not Refreshing Page Terry Cox, MCSD ASP .Net 0 10-24-2003 08:53 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57