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

Getting alert on GridHyperLinkColumn Click

3 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
h@r!
Top achievements
Rank 1
h@r! asked on 27 Sep 2010, 10:11 AM
Hi ,

I am working on RadGrid and I need to get a alert on GridHyperLinkColumn click in the radgrid just as I get by using GridEditCommandColumn while editing the record if the user is not authorised to edit the data.Otherwise how can I give the Command Name for the GridHyperLinkColumn so that i can handle it in the codebehind.

Thanks,
h@r!.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Sep 2010, 10:46 AM
Hello Hari,

You can achieve this by finding the HyperLink in the GridHyperLink column and set its "onclick" attribute.

ASPX:
<telerik:GridHyperLinkColumn DataTextField="CompanyName" DataNavigateUrlFields="CompanyName"  UniqueName="GridHyperLinkColumn"></telerik:GridHyperLinkColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            HyperLink link = (HyperLink)item["GridHyperLinkColumn"].Controls[0];
            link.Attributes.Add("onclick", "Validate(); return false;");
        }
    }

Java Script:
<script type="text/javascript">
    function Validate() {
        alert("Not an authorized user");
    }
</script>

Thanks,
Princy.
0
h@r!
Top achievements
Rank 1
answered on 27 Sep 2010, 11:28 AM
Hi Princy,

Thanks for the Reply :)

But it is not working in my scenario.Let me explain my case clearly.

I am having Grid with values binded using GridBoundColumn.And I need to check the values in the GridBoundColumn and if they are null I need to alert when the user clicks Edit link.
like
<telerik:GridHyperLinkColumn DataTextFormatString="Edit" DataNavigateUrlFields="SRowId" Text="Edit" UniqueName="SRowId"  DataNavigateUrlFormatString="Test.aspx?Row={0}" ></telerik:GridHyperLinkColumn
<telerik:GridBoundColumn DataField="Company" HeaderText="Company" />

                        
and I need to check if Company="" and if the user clicks the Edit which is a GridHyperLinkColumn  I need to give an alert as 'User unauthorised' and if Company!="" then he can proceed to edit the row.

Hope it explains the case clearly.

Thanks,
h@r!.
0
Princy
Top achievements
Rank 2
answered on 28 Sep 2010, 11:04 AM
Hello Hari,

You can do that validation with the cell value of GridBoundColumn from client side by using its ColumnUniqueName. Check out the following code snippet.

ASPX:
<telerik:GridHyperLinkColumn DataTextFormatString="Edit" DataNavigateUrlFields="SRowId" Text="Edit" UniqueName="SRowId"  DataNavigateUrlFormatString="Test.aspx?Row={0}" ></telerik:GridHyperLinkColumn>
<telerik:GridBoundColumn DataField="Company" HeaderText="Company" UniqueName="Company"   />

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           HyperLink link = (HyperLink)item["SRowId"].Controls[0];
           link.Attributes.Add("onclick", "return Validate('" + item.ItemIndex + "');");
       }
   }

Java Script:
<script type="text/javascript">
     function Validate(index) {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var row = MasterTable.get_dataItems()[index];
        var cell = MasterTable.getCellByColumnUniqueName(row, "Company").innerHTML; // access the cell value of column Company using its column UniqueName
        if (cell == " ") {
            alert("Not an authorized user");
            return false;
        }
        else
            return true;
    }
 </script>

Thanks,
Princy.
Tags
Grid
Asked by
h@r!
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
h@r!
Top achievements
Rank 1
Share this question
or