Button Events in UserControl embedded in a Datagrid

K

Kalpesh

Hello,

I have a WebUserControl in which there are Link Button and
Buttons, I have made public properties for this button.

now this control i am using it inside a datagrid
and then in datagrid's ItemDataBound event i am writing
following code.

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
VBAccomSearchResultsProductView ctrl =
(VBAccomSearchResultsProductView) e.Item.FindControl
("ProductListView");

if(ctrl!=null)
{
DataRowView drv = (DataRowView) e.Item.DataItem;
ctrl.ProductID=int.Parse(drv[0].ToString());
ctrl.LBtnProductName.Text=drv[0].ToString();
ctrl.BtnAddToItinerary.Click+=new EventHandler
(BtnAddToItinerary_Click);
}
}

the problem is Click Event of BtnAddToItinerary is not
firing.
pls tell me what am i doing wrong.

thanx,
Kalpesh
 
K

Kalpesh

Hi Lewis,

Thanx, Your reply solves my query.
I have also got one another query.

In the datagrid, the paging facility provided is not
giving the desired looks & features.
Like for example in this way:

[Title] [Total Records found] <Previous 1,2,3,4,5....
Next>

Is there anyway i can customize the paging like that in
datagrid, or will i have to make a custom control or is
there any ready made control available in .net

Regards,
Kalpesh


-----Original Message-----
Hi Kalpesh,

You can add an ItemCommand event to your datagrid (in the properties of the
grid ->events->double click ItemCommand option). When any button is clicked
in the datagird, DataGrid1_ItemCommand will be triggered , even if the
button is in a webcontrol.

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int whichitem=e.Item.ItemIndex;//Get the index of the item.
//e.CommandSource is the control you have clicked.
string s3=((Button)
(e.CommandSource)).ClientID; //Get the ID of the
button you have clicked.
}

I would also like to recommend one good article to you:

Adding Button Columns to a DataGrid Web Server Control
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/vbcon/html/
vbtskaddingbuttoncolumnstodatagridwebcontrol.asp

Does this answer your question? Please let me know if you need more
information.

Best Regards,
Lewis Wang

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Kalpesh" <[email protected]>
| Sender: "Kalpesh" <[email protected]>
| Subject: Button Events in UserControl embedded in a Datagrid
| Date: Fri, 18 Jul 2003 04:15:25 -0700
| Lines: 32
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNNHeL1/mmELc50RqavVd2PliReew==
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:13240
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hello,
|
| I have a WebUserControl in which there are Link Button and
| Buttons, I have made public properties for this button.
|
| now this control i am using it inside a datagrid
| and then in datagrid's ItemDataBound event i am writing
| following code.
|
| private void DataGrid1_ItemDataBound(object sender,
| System.Web.UI.WebControls.DataGridItemEventArgs e)
| {
| VBAccomSearchResultsProductView ctrl =
| (VBAccomSearchResultsProductView) e.Item.FindControl
| ("ProductListView");
|
| if(ctrl!=null)
| {
| DataRowView drv = (DataRowView) e.Item.DataItem;
| ctrl.ProductID=int.Parse(drv[0].ToString());
| ctrl.LBtnProductName.Text=drv[0].ToString();
| ctrl.BtnAddToItinerary.Click+=new EventHandler
| (BtnAddToItinerary_Click);
| }
| }
|
| the problem is Click Event of BtnAddToItinerary is not
| firing.
| pls tell me what am i doing wrong.
|
| thanx,
| Kalpesh
|

.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top