datagrid

S

Steph

Hello,

I have a datagrid dgGrid and want add column depending of a context. I am
usin this following code :

....
while (Clcpt<7)
{
ButtonColumn myCol = new ButtonColumn();
myCol.HeaderText = Clcpt.ToString();
myCol.ButtonType = ButtonColumnType.LinkButton;
myCol.Text = "<img src='images/Add.gif' border=0>";
myCol.CommandName = "cmd"+Clcpt;
Response.Write("cmd"+Clcpt+"/");
dgGrid.Columns.Add(myCol);
Clcpt++;
}
...
Cols are ok but I can't intercept the clik on the button. I have an event
handler dgDrid_ItemCommand but it is never fired ?

Any idea ?

thanks
 
G

Guest

First, it does not look like you attach an event handler to the button.

Second, you must add the same column and event handler on postback.

The way the postback architecture works, it needs a *context* to capture the
triggering control. Since HTTP is stateless, it recreates the control
hierarchy on postback and then any events that are related to the controls
are triggered.

If you don't want to get too involved in the .Net page/postback
architecture, the easiest solution is to simply attach a query string to the
link manually and capture the click using Request.QueryString or Request.Form
(if you use hidden inputs on the client side). Not necessarily pretty, but
the easiest solution.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top