2012年3月10日土曜日

Row clickable functionality for gridview using AJAX.Net beta 2

The actual problem lies in this line

e.Row.Cells(i).Attributes.Add("onClick",ClientScript.GetPostBackEventReference(Me, e.Row.DataItemIndex.ToString()))

the "Me" keyword which is the target control indicates the page. Its like creating a new event for the page. Hence a postback occurs as the target control i.e. the page will have to be refreshed on this event. This seemed to work without a postback in the older version (ATLAS) but causes postback in the new version (AJAX.NET).

The solution we have found to this is :

Dim pbAs PostBackOptions =New PostBackOptions(GVLines,"Edit$" & e.Row.DataItemIndex.ToString())

e.Row.Cells(intCounter).Attributes.Add(

"onClick", Page.ClientScript.GetPostBackEventReference(pb))

this makes the event target as the grid GVLines and causes only the grid to refresh.

There wont be any need for implementing theIPostBackEventHandler interface as we are not creating events for page but rather the GridView and the event that is called is same as the RowEditing event.

This however does not work if the edit command field is not present the problem being the evnetvalidation of the page fails.

The solution is to have an edit command field .If its in use then no probs otherwise set the style to display:none as below

<asp:CommandFieldShowEditButton="True"Visible="true"HeaderStyle-CssClass="hidden"ItemStyle-CssClass="hidden"FooterStyle-CssClass="hidden"/>

the CssClass set the style as display:none

This should solve the problem

Sohail Sayed

IOTap

0 件のコメント:

コメントを投稿