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

RadGrid Image button Column Click

2 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nithya Rani
Top achievements
Rank 1
Nithya Rani asked on 05 Mar 2012, 08:16 AM
Hi

I have a Imagebutton in my RadGrid. During the OnClientClick of the image button i need to get the DataKeyNames and the Command Argument value of the imagebutton in my client side.

Regards
Nithya

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Mar 2012, 12:24 PM
Hello Nithya Rani ,

<script type="text/javascript">
           function MyClick(skey, sarg) {
               alert(skey);
               alert(sarg);
               return false;
                
           }
       </script>
<telerik:GridTemplateColumn>
                      <ItemTemplate>
                          <asp:Button ID="btnTest" Text="Test" runat="server" />
                      </ItemTemplate>
</telerik:GridTemplateColumn>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            Button btnTest = item.FindControl("btnTest") as Button;
            string strKey = item.GetDataKeyValue("ThresholdNumber").ToString();
            string strArgument = "yourArgument";
            btnTest.Attributes.Add("onclick", "return MyClick('" + strKey + "','" + strArgument + "');");
        }
    }

Let me know If any concern.

Thanks,
Jayesh Goyani
0
Erena
Top achievements
Rank 1
answered on 14 Feb 2013, 09:25 PM
Inside your RadGrid control create a OnRowClick ClientEvent inside the ClientSettings section:

i.e.
<telerik:RadGrid ID="RadGridTimeSlot1" runat="server"

 

 DataSourceID="odsAvailable0" GridLines="None" Height="165"

 OnItemCommand="RadGridTimeSlot1_ItemCommand" Skin="Web20" Width="117">

 <ClientSettings Scrolling-AllowScroll="true"

 Scrolling-SaveScrollPosition="true" Scrolling-UseStaticHeaders="true">

 <Selecting AllowRowSelect="True" />

 <ClientEvents OnRowClick="RowClick" /> </

ClientSettings>
<MasterTableView AutoGenerateColumns="False" DataKeyNames="SlotID,StartTime" ClientDataKeyNames="ApptTimeSlotID,StartTime" DataSourceID="odsAvailable0" 
EnableNoRecordsTemplate="true" ShowHeader="true">

<ItemStyle CssClass="UseHand" />
<AlternatingItemStyle CssClass="UseHand" />
<Columns>
<telerik:GridTemplateColumn UniqueName="ApptColumn">
<ItemTemplate> 
    <%#Eval("StartTime", "{0:t}")%>
</ItemTemplate>
<HeaderTemplate>
    <%# DateAdd(DateInterval.Day, 0, CDate(rdpDate.SelectedDate())).ToString("dddd<br>MMMM d")%>
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="90" />
<HeaderStyle HorizontalAlign="Center" Width="90" />
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate> 
    No schedule available for this date.
</NoRecordsTemplate>
</MasterTableView>

2. Create a JavaScript RowClick event handler, which will get the data keys in the RadGrid that the RowClick client side event was fired on:


function
RowClick(sender, eventArgs) {
var MasterTable = sender.get_masterTableView();
var StartTime = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()].getDataKeyValue("StartTime"); 
return
false;

}

 

 

 

 

 

Tags
Grid
Asked by
Nithya Rani
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Erena
Top achievements
Rank 1
Share this question
or