1

I use a repeater Control to display all the comments from Datatable:

COMMENT(id,content,time);

In repeater I insert a button Delete to Delete that correlative comment

I wonder if I can add an variable "string id" in ButtonDelete_Click() like:

protected void ButtonDelete_Click(object sender, EventArgs e, string id)
{
     int idcm = Convert.ToInt32(id);
     string sql = "delete from COMMENT where ID=" + idcm;
     l.EXECUTEQUERYSQL(sql);
     ErrorTrap("DONE");//alert deleted sucessfully
}

And in aspx page:

<Repeater...>
    <asp:Button ID="ButtonDelete" runat="server" Text="Delete comment" 
         OnClick="ButtonDelete_Click(<%#Eval("MA_COMMENT") %>)"/>
    ....
</Repeater>

But when I build this page, an error ocur: The server tag is not well formed. at line:

<asp:Button ID="ButtonDelete" runat="server" Text="Delete comment" 
     OnClick="ButtonDelete_Click(<%#Eval("MA_COMMENT") %>)"/>

It is the first time I use Repeater Control, so I really dont know how is the right syntax? And I wonder if I can add more variales in ButtonDelete_Click Event or not???

Help!

शेखर
  • 17,412
  • 13
  • 61
  • 117
vyclarks
  • 854
  • 2
  • 15
  • 39

2 Answers2

1

you can use the command argument property fot the button and grap it in the click event :

<asp:Button ID="ButtonDelete" runat="server" Text="Delete comment" 
         OnClick="ButtonDelete_Click()" CommandArgument='<%#Eval("MA_COMMENT") %>'/>

on the click event

void ButtonDelete (object sender, EventArgs e)
  {

     var id = int.parse(e.CommandArgument.ToString());

  }

Hope this is helpful

user123456
  • 2,524
  • 7
  • 30
  • 57
  • thanks, but in cs page, it has an error: cannot resolve symbol CommandArgument. Help??? – vyclarks Oct 03 '13 at 05:31
  • Thank, I use void ButtonDelete (object sender, CommandEventArgs e) and then call it: OnCommand="ButtonDelete_Click" CommandArgument='<%#Eval("MA_COMMENT") %>' --> It works, thank you ^^ – vyclarks Oct 03 '13 at 05:49
0

use this

OnClick='ButtonDelete_Click(<%#Eval("MA_COMMENT") %>)'

or try replacing ' to " it should work.

Edit 1

More details

  1. The server tag is not well formed
  2. The server tag is not well formed.(databinder.eval)
  3. error The server tag is not well formed
  4. The server tag is not well formed error
Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • thank you, but when I replace ' to ", it still doesnt work: CS1040: Preprocessor directives must appear as the first non-whitespace character on a line – vyclarks Oct 03 '13 at 05:35