This is a migrated thread and some comments may be shown as answers.

how to call method on grid row click?

4 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ajmal
Top achievements
Rank 1
ajmal asked on 29 Nov 2010, 03:24 PM
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;

 

}

}

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 29 Nov 2010, 06:12 PM
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.
0
ajmal
Top achievements
Rank 1
answered on 30 Nov 2010, 05:11 AM
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());

}

0
Veli
Telerik team
answered on 30 Nov 2010, 08:33 AM
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.
0
ajmal
Top achievements
Rank 1
answered on 30 Nov 2010, 12:17 PM
could you please suggest some solution?
Tags
Grid
Asked by
ajmal
Top achievements
Rank 1
Answers by
Veli
Telerik team
ajmal
Top achievements
Rank 1
Share this question
or