Datagrid ButtonColumn short Question

G

Guest

Hi,

Im making a web custom datagrid of products.

I have this piece of code in the override OnInit Method:

ButtonColumn colbtn=new ButtonColumn();

colbtn.ButtonType=ButtonColumnType.LinkButton;

colbtn.Text="<a href=# onclick=alert("+")>See Product</a>";

How could i know what link is pressed by the user?,

i would like to have a link buton in each row of the datagrid, and when a user clicks on it open a popup and pass the ID of the product to the page that im opening?

Thanks
Josema.
 
O

Ollie

what i do is when the data grid is created I add an event handler to the
button

e.g.

private void XXXDataGrid_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType ==
ListItemType.AlternatingItem)
{
System.Web.UI.WebControls.Button btSelect = null;
btSelect = (System.Web.UI.WebControls.Button)e.Item.FindControl("btSelect");
btSelect.Click += new EventHandler(btSelect_Click);
}
}

And then in the event handler do something like this....


private void btSelect_Click(object sender, EventArgs e)
{
System.Web.UI.WebControls.Button btSelect = null;
btSelect = (System.Web.UI.WebControls.Button)sender;

System.Web.UI.WebControls.DataGridItem item = null;
item = (System.Web.UI.WebControls.DataGridItem)btSelect.Parent.Parent;

//DO SOMETHING WITH THE CURRENT DATAGRID ITEM, USUALLY USE THE
// item.Index property to access a row in the collection bound to the
datagrid, watch out for
// page indexing if you are using that....
}

Hope this helps

Ollie


Josema said:
Hi,

Im making a web custom datagrid of products.

I have this piece of code in the override OnInit Method:

ButtonColumn colbtn=new ButtonColumn();

colbtn.ButtonType=ButtonColumnType.LinkButton;

colbtn.Text="<a href=# onclick=alert("+")>See Product</a>";

How could i know what link is pressed by the user?,

i would like to have a link buton in each row of the datagrid, and when a
user clicks on it open a popup and pass the ID of the product to the page
that im opening?
 

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

Top