how to call method on grid row click?

5 posts, 0 answers
  1. ajmal
    ajmal avatar
    57 posts
    Member since:
    Oct 2006

    Posted 29 Nov 2010 Link to this post

    Hello All,

    I having a grid in which we create control dynamically in their header which will perfectly loaded below below on

    ItemDataBound

    method.

    Method CreateHeaderControls(e); is doesn't call while we click a record on click which will call below method,

    Is there any possibility to call CreateHeaderControls(e); in method RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)

    or else any alternate..thnx please help?

     

     


     

    protected

     

    override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)

     

    {

     

    try

     

     

     

     

    {

     

    base.RaisePostBackEvent(source, eventArgument);

     

     

    if (source == this.grdADInbox && eventArgument.IndexOf("RowDblClicked") != -1)

     

    {

     

    RadGrid rg = (RadGrid)source;

     

     

    int index = int.Parse(eventArgument.Split(':')[1]);

     

     

    ========================================================================

     

    protected

     

    void grdADInbox_ItemDataBound(object sender, GridItemEventArgs e)

     

    {

    CreateHeaderControls(e);

    }



    private

     

    void CreateHeaderControls(GridItemEventArgs args)

     

    {

     

    Button btnGroupApprove = new Button();

     

     

    Button btnGroupReject = new Button();

     

     

    String tranType = String.Empty;

     

     

    Int32 tranCount = 0;

     

     

    try

     

    {

     

     

    if (args.Item is GridGroupHeaderItem)

     

    {

     

    GridGroupHeaderItem item = args.Item as GridGroupHeaderItem;

     

     

     

    DataRowView groupDataRow = (DataRowView)args.Item.DataItem;

     

     

    if (groupDataRow != null)

     

    {

    tranType =

    ((System.Data.

    DataRowView) (((Telerik.Web.UI.GridGroupHeaderItem) item).DataItem)).Row.ItemArray

     

    .GetValue(0).ToString();

    tranCount =

     

    Convert.ToInt32(((System.Data.DataRowView)(((Telerik.Web.UI.GridGroupHeaderItem)item).DataItem)).Row.ItemArray

     

    .GetValue(1).ToString());

    }

     

     

    btnGroupApprove.ID =

    "btnGroupApprove";

     

    btnGroupApprove.Text =

    "Approve All";

     

    btnGroupReject.ID =

    "btnGroupReject";

     

    btnGroupReject.Text =

    "Reject All";

     

     

    Label lbl = new Label();

     

    lbl.ID =

    "lblGroup";

     

     

    String strGroupingText = item.DataCell.Text;

     

     

    if (strGroupingText != " ")

     

    {

     

    if (strGroupingText.Contains("("))

     

    {

    strGroupingText = strGroupingText.Remove(strGroupingText.IndexOf(

    "("));

     

    }

    lbl.Text = strGroupingText.Insert(strGroupingText.IndexOf(

    "Total"), "                                                       ");

     

    lbl.Text +=

    "               ";

     

    item.DataCell.Controls.Add(lbl);

    }

    item.DataCell.Controls.Add(btnGroupApprove);

    item.DataCell.Controls.Add(btnGroupReject);

    }

     

    string strApproveUrl = "ApproveAction.aspx?action=GroupApprove&&Tran_Type=" + tranType + "&&Tran_Count=" + tranCount;

     

     

    string strRejectUrl = "ApproveAction.aspx?action=GroupReject&&Tran_Type=" + tranType + "&&Tran_Count=" + tranCount;

     

    btnGroupApprove.Attributes.Add(

    "onclick", "return ShowApprovalPopUp('" + strApproveUrl + "');");

     

    btnGroupReject.Attributes.Add(

    "onclick", "return ShowApprovalPopUp('" + strRejectUrl + "');");

     

    }

     

    catch (Exception ex)

     

    {

     

    throw ex;

     

    }

    }

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 29 Nov 2010 Link to this post

    Hi ajmal,

    You need to call CreateHeaderControls() both in the ItemCreated and ItemDataBound events. The reason for that is because ItemDataBound alone is not fired on every postback. It is fired when RadGrid rebinds and items are recreated. So, you cannot count on it firing on every postback. You need to use ItemCreated too. ItemCreated fires on every postback, but it does so before ItemDataBound. This means controls created in ItemCreated will be gone when ItemDataBound fires. So, in effect, you need to use both ItemCreated and ItemDataBound to initialize one and the same controls.

    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ajmal
    ajmal avatar
    57 posts
    Member since:
    Oct 2006

    Posted 29 Nov 2010 Link to this post

    well...

    I also call CreateHeaderControls() in the ItemCreated, but below code doesn't execute,

    if

     

    (args.Item is GridGroupHeaderItem)

     

    {

     

    GridGroupHeaderItem item = args.Item as GridGroupHeaderItem;

     

     

     

    DataRowView groupDataRow = (DataRowView)args.Item.DataItem;

     

     

    if (groupDataRow != null)

     

    {

    tranType =

    ((System.Data.

    DataRowView) (((Telerik.Web.UI.GridGroupHeaderItem) item).DataItem)).Row.ItemArray

     

    .GetValue(0).ToString();

    tranCount =

     

    Convert.ToInt32(((System.Data.DataRowView)(((Telerik.Web.UI.GridGroupHeaderItem)item).DataItem)).Row.ItemArray

     

    .GetValue(1).ToString());

    }

  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 30 Nov 2010 Link to this post

    Hello ajmal,

    In ItemCreated you do not have the args.Item.DataItem. This is because your item is not databound yet. It is only created. So, you need to create your controls in it without trying to bind them. Binding should happen in ItemDataBound.

    Greetings,
    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  6. ajmal
    ajmal avatar
    57 posts
    Member since:
    Oct 2006

    Posted 30 Nov 2010 Link to this post

    could you please suggest some solution?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017