


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 :
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);
}
}

danish ahmedPosted Nov 25, 2014, 4:06 AM
It worked :)
Wim SturkenboomPosted Nov 24, 2014, 11:37 AM
if (e.CommandName == "Permissions")
{
lblSelectedUserID.Text = e.Item.Cells[0].Text;
lblSelectedUserName.Text = e.Item.Cells[1].Text;
}
Hope this helps.
// OOPS, this is for a datagrid, might not work for a gridview; you'll just have to try.