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

RadGrid not ajaxfying on linkbutton click

6 Answers 282 Views
Grid
This is a migrated thread and some comments may be shown as answers.
NITHIN
Top achievements
Rank 1
NITHIN asked on 16 Feb 2012, 01:09 PM
i having a rad grid with item template column consist of link button.i need to update the grid when i click the link button.

currently i am using radajaxmanger with ajax request function .but my grid doesnt get updated.
my code snippets are below
<telerik:RadGrid runat="server" ID="uxAlerts" OnItemCreated="uxAlerts_ItemCreated" OnNeedDataSource="uxAlerts_NeedDataSource"  OnItemDataBound="uxAlerts_OnItemDataBound" Skin="Simple" AllowPaging="True" AllowSorting="True"
                    CellSpacing="0" GridLines="Both" CssClass="Grid" AutoGenerateColumns="false"
                    ShowHeader="true">
                    <MasterTableView>
                        <Columns>
                            <telerik:GridBoundColumn DataField="Subject" HeaderText="Subject" HeaderStyle-HorizontalAlign="Left">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="AssignedTo" HeaderText="Assigned To" HeaderStyle-HorizontalAlign="Left"
                                ItemStyle-Width="200px">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="CreatedDate" HeaderText="Date/Time" ItemStyle-Width="100px"
                                ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn HeaderText="Action" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center"
                                HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="uxUnread"  runat="server" Text='<%# Bind("ReadStatus")%>'></asp:LinkButton>
                                    <asp:LinkButton ID="uxClose"  Text="Close"  runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
<telerik:RadAjaxLoadingPanel runat="server" Skin="Default" ID="uxLoadingPanel" />
                    <telerik:RadAjaxManager ID="uxRadAjaxManager" runat="server" OnAjaxRequest="uxRadAjaxManager_AjaxRequest">
                        <AjaxSettings>
                            <telerik:AjaxSetting AjaxControlID="uxAlerts">
                                <UpdatedControls>
                                    <telerik:AjaxUpdatedControl ControlID="uxAlerts" LoadingPanelID="uxLoadingPanel" />
                                </UpdatedControls>
                            </telerik:AjaxSetting>
                        </AjaxSettings>
                    </telerik:RadAjaxManager>
and js func is

function CloseClick(index) {
            var ajaxManager = $find("<%= uxRadAjaxManager.ClientID %>");
               if (ajaxManager != null)
                {
                   ajaxManager.ajaxRequest(index);
               }

and cs func are
protected void uxAlerts_OnItemDataBound(object sender, GridItemEventArgs e)
        {

            if (e.Item is GridDataItem)
            {
                CaseAlert caseAlertDetails = e.Item.DataItem as CaseAlert;
                if (caseAlertDetails != null)
                {
                    GridDataItem dataItem = (GridDataItem)e.Item;
                    LinkButton rblHyperLink = (e.Item.FindControl("uxClose") as LinkButton);
 
                    string alertID = caseAlertDetails.Id.ToString();

                    rblHyperLink.OnClientClick = string.Format("return CloseClick('" + alertID + "');");


                }
            }
        }
protected void uxRadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument != null)
            {
                //uxAlerts.DataSource = new List<CaseAlert>();
                //uxAlerts.DataBind();
          
                    
                }

            
        }

When i click close link button it works and it calls ajax request but i dnt find any loading panel working on grid and no update on grid

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Feb 2012, 01:26 PM
Hello,

Try calling Rebind() method in ajax request by checking for the argument.

Thanks,
Princy.
0
NITHIN
Top achievements
Rank 1
answered on 16 Feb 2012, 01:31 PM
iam alredy used that but no effect. when i make a call to ajaxrequest from js it will not show the loading panel.but call going to server side func.and do the stuff like u said rebind() or clear().but the problem is UI doesnt reflect anything.
0
Accepted
Casey
Top achievements
Rank 1
answered on 16 Feb 2012, 02:48 PM
Hi Nithin,

I would recommend adding the OnItemCommand event to the RadGrid, and then specify the LinkButton's CommandName, then you could do what you needed in the uxAlerts_ItemCommand event, which would be done using Ajax since you specify uxAlerts updates uxAlerts.

I hope this helps!
Casey

OnItemCommand="uxAlerts_ItemCommand"

<asp:LinkButton ID="uxUnread"  runat="server" Text='<%# Bind("ReadStatus")%>' CommandName="Unread"></asp:LinkButton>

protected void uxAlerts_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Unread")
        {
            GridDataItem dataItm = e.Item as GridDataItem;
            LinkButton lbUnread = dataItm.FindControl("uxUnread") as LinkButton;
                //Your code here
                uxAlerts.Rebind();
        }
}
0
NITHIN
Top achievements
Rank 1
answered on 17 Feb 2012, 05:16 AM
 in that case how can i get grid bound column value?

CaseAlert caseAlert = e.Item.DataItem as CaseAlert;

but i got it as null because of e is an GridCommandEventArgs.is there anyway getting gridbound column values?
0
NITHIN
Top achievements
Rank 1
answered on 17 Feb 2012, 07:46 AM
i got the result by using ((GridDataItem)e.Item).GetDataKeyValue("col1").ToString();

thank you for the solution casey.it works fine for my scenario.thank you for your support..
0
Casey
Top achievements
Rank 1
answered on 17 Feb 2012, 02:03 PM
Hi Nithin,

Glad I could help!

I normally use the following to access the column values for the row that was clicked.

protected void uxAlerts_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Unread")
        {
            GridDataItem dataItm = e.Item as GridDataItem;
            LinkButton lbUnread = dataItm.FindControl("uxUnread") as LinkButton;
            //you can replace col1 with any of your columns' UniqueNames
            String val = dataItm["col1"].Text;
            uxAlerts.Rebind();
        }
}
Tags
Grid
Asked by
NITHIN
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
NITHIN
Top achievements
Rank 1
Casey
Top achievements
Rank 1
Share this question
or