Button Events in UserControl embedded in a Datagrid

Discussion in 'ASP .Net Web Controls' started by Kalpesh, Jul 18, 2003.

  1. Kalpesh

    Kalpesh Guest

    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
     
    Kalpesh, Jul 18, 2003
    #1
    1. Advertising

  2. Kalpesh

    Kalpesh Guest

    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" <>
    >| Sender: "Kalpesh" <>
    >| Subject: Button Events in UserControl embedded in a

    Datagrid
    >| Date: Fri, 18 Jul 2003 04:15:25 -0700
    >| Lines: 32
    >| Message-ID: <097c01c34d1d$e2f80040$>
    >| 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
    >|
    >
    >.
    >
     
    Kalpesh, Jul 23, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    684
    gover
    May 6, 2007
  2. Brian

    UserControl Button Events

    Brian, Jul 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    115
    Brian
    Jul 28, 2004
  3. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    426
    Thomas Dodds
    Jul 26, 2004
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    418
    Chris
    Aug 30, 2005
  5. Num GG
    Replies:
    2
    Views:
    407
    Num GG
    Nov 17, 2008
Loading...

Share This Page