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

Accessing Cells in RadGrid On Click

1 Answer 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike_T
Top achievements
Rank 1
Mike_T asked on 10 Apr 2010, 11:01 AM
Hello,
Is it possible to do the following?

I am building my grid from code behind dynamically, i need to do 2 things:
1. After i draw the grid, i need to write specific data by (Client/Category)
2. When i click on a specific cell it should open a window that will pass the Client and Category of the clicked cell to the window.

I'm attaching the code i'm using

<

 

telerik:RadGrid ID="RadGrid1" Width="100%" runat="server" CellPadding="0" AutoGenerateColumns="false" GridLines="Both"  HorizontalAlign="NotSet" ClientSettings-AllowColumnsReorder="false" ClientSettings-ReorderColumnsOnClient="false"

 

 

 

AllowSorting="false" FilterItemStyle-HorizontalAlign="Center" FilterItemStyle-VerticalAlign="middle"> 

 

 

<clientsettings EnablePostBackOnRowClick="true">

 

<ClientEvents />

 

 

<Selecting AllowRowSelect="True" ></Selecting> 

 

<Scrolling EnableVirtualScrollPaging="true" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="1"/>

 

</clientsettings 

 

 

<mastertableview borderstyle="None" datakeynames="ClientID1">  

 

</mastertableview 

 

</telerik:RadGrid

 


 

Private Sub Test_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

Dim dt1 As DataTable = Dac.ExecuteDataTable("usp_rr_admin_pc_getClients", Nothing)

 

 

 

Dim objDT = dt1

 

 

 

 

 

If RadGrid1.Columns.Count > 0 Then

 

 

RadGrid1.Columns.Clear()

 

End If

 

 

objDT.Columns.Add(

"ClientNameAR1", GetType(String))

 

 

 

Dim ogridcolumn As GridBoundColumn

 

 

ogridcolumn =

New GridBoundColumn

 

 

 ogridcolumn.Visible =

True

 

 

 

ogridcolumn.HeaderText = "ClientNameAR"

 

 

 

ogridcolumn.DataField = "ClientNameAR"

 

 

 

ogridcolumn.HeaderStyle.Width = "70"

 

 

 

ogridcolumn.ItemStyle.Width = "70"

 

 

 

ogridcolumn.ItemStyle.BorderColor = Drawing.Color.Black

 

RadGrid1.Columns.Add(ogridcolumn)

 

objDT.Columns.Add(

"ClientID1", GetType(String))

 

 

ogridcolumn =

New GridBoundColumn

 

 

ogridcolumn.HeaderText =

"ClientID"

 

 

 

ogridcolumn.DataField = "ClientID"

 

 

 

ogridcolumn.Visible = True

 

 

 

ogridcolumn.ItemStyle.BorderColor = Drawing.Color.Black

 

RadGrid1.Columns.Add(ogridcolumn)

 

Dim dt3 As DataTable = Dac.ExecuteDataTable("usp_rr_admin_pc_getCategories", Nothing)

 

 

 

For Each drRow As DataRow In dt3.Rows

 

 

 

Dim val As String = drRow.Item("CategoryAR").ToString

 

objDT.Columns.Add(val)

ogridcolumn =

 

New GridBoundColumn

 

ogridcolumn.Visible =

 

True

 

 

ogridcolumn.DataField = val

ogridcolumn.HeaderText = val

ogridcolumn.UniqueName = val

ogridcolumn.HeaderStyle.Width =

"70"

 

 

ogridcolumn.ItemStyle.Width =

"70"

 

 

ogridcolumn.ItemStyle.BorderColor = Drawing.Color.Black

RadGrid1.Columns.Add(ogridcolumn)

 

Dim val1 As String = drRow.Item("CategoryID").ToString

 

objDT.Columns.Add(val1)

ogridcolumn =

 

New GridBoundColumn

 

ogridcolumn.Visible =

 

True

 

 

ogridcolumn.DataField = val1

ogridcolumn.HeaderText = val1

ogridcolumn.UniqueName = val1

ogridcolumn.ItemStyle.BorderColor = Drawing.Color.Black

RadGrid1.Columns.Add(ogridcolumn)

 

Next

 

 

ogridcolumn =

Nothing

 

 

 

Dim dt2 As DataTable = Dac.ExecuteDataTable("usp_rr_admin_pc_getClients", Nothing)

 

 

 

For Each dr As DataRow In dt2.Rows

 

objDR = objDT.NewRow

objDR(

 

"ClientID1") = dr("ClientID")

 

objDR(

 

"ClientNameAR1") = dr("ClientNameAR")

 

objDT.Rows.Add(objDR)

 

 

Next

 

 

dt2.Dispose()

dt2 =

Nothing

 

 

RadGrid1.DataSource = objDT

RadGrid1.DataBind()

objDT.Dispose()

objDT =

Nothing

 

 

RadGrid1.MasterTableView.Dir = GridTableTextDirection.RTL

 

End Sub

 

 


1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Apr 2010, 07:00 AM

Hello Mike,

I hope the demo will be helpful in getting started on how to pass the clicked cell value to client side.

Edit Dialog for RadGrid

Also checkout the forum link shown below that shows how to attach click event to grid cells.

On a mouse click on Grid, how to get ColumnIndex/RowIndex on client side?

 

-Shinu.

Tags
Grid
Asked by
Mike_T
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or