danish  ahmed

danish ahmed

  • NA
  • 8
  • 1.8k

Grid view Button help?

Nov 24 2014 7:51 AM


I am creating web app.
This is a grid view last column has button send message.
When Admin click on send message dynamically a label (to hold emp id),
textbox (to type message), a button (to perform send operation) wil be created.
Problem : Unable to get generate label dynamically to hold emp id on label text.
event : Working on row command event.
Code:
1. Aspx : <asp:ButtonField ButtonType="Button" HeaderText="Message" CommandName="Message" Text="Send Message" />
2. aspx.cs : protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Message")
{
Label lbl = new Label();
lbl.Text = GridView1.SelectedRow.Cells[0].Text; // gets error here i think logic is wrong here //
Panel1.Controls.Add(lbl);
TextBox txtbx = new TextBox();
txtbx.Text = "Enter message for Employee ";
Panel1.Controls.Add(txtbx);
Button btnsubmit = new Button();
btnsubmit.Text = "Send Message ";
Panel1.Controls.Add(btnsubmit);
}
}

Answers (2)