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

[Solved] Getting a Cell's Value

5 Answers 328 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 29 Apr 2008, 11:23 PM

Using the classic rad grid I was able to get a cell's value by doing the following:
VB code:

Public

Function GetDataTable(ByVal query As String) As DataTable

Dim connection2 As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ENG101Exam.accdb;Persist" & _

" Security Info=True")

Dim adapter2 As New OleDbDataAdapter

adapter2.SelectCommand =

New OleDbCommand(query, connection2)

Dim table2 As New DataTable

connection2.Open()

Try

adapter2.Fill(table2)

Finally

connection2.Close()

End Try

Return table2

End Function

 

Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

RadGrid1.DataSource = GetDataTable(

"SELECT Teacher FROM [Teacher List] ")

End Sub

I can't get these routines to work using the grid for ASP.NET AJAX. 
Can anyone help?

Thanks,
Tony

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Apr 2008, 04:33 AM
Hi Tony,

Go through the following help document link which discusses on how to access cell values.
Accessing cells and rows

Thanks
Princy.
0
C5 Insight
Top achievements
Rank 1
answered on 27 Jun 2008, 03:00 PM
All,

I think I am close, but can't seem to get the client-side events to give the data I think they should. 

At this point, all I am trying to accomplish is attach an onclick event to each cell, so its color will change when clicked.

I have followed the following example: http://www.telerik.com/help/aspnet/grid/grdselectingcells.html but the row.Control is not giving what I expect.  I thought row.Control would give me the <tr> object, but this is what I'm receiving:

<DIV class=GridHeaderDiv_Office2007 id=SelectedRespondents_GridHeader style="PADDING-RIGHT: 16px; OVERFLOW: hidden">
<TABLE class=MasterTable_Office2007 id=SelectedRespondents_ctl00_Header style="TABLE-LAYOUT: fixed; OVERFLOW: hidden; WIDTH: 100%; BORDER-COLLAPSE: collapse; TEXT-OVERFLOW: ellipsis; empty-cells: show" cellSpacing=0 border=0>
<COLGROUP>
<COL width=135>
<COL width=125>
<COL width=75>
<COL width=50>
<COL width=150>
<COL width=50>
<COL width=35>
<COL width=35>
<COL width=75>
<COL width=75>
<COL width=75></COLGROUP>
<THEAD>
<TR>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl01','')">Respondent Number</A>&nbsp;<INPUT class=rgSortAsc title="Sorted asc" originalAttribute="href" originalPath="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl01','')">Respondent Number</A>&nbsp;<INPUT class=rgSortAsc title="Sorted asc" onclick="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl02','')" type=button name=SelectedRespondents$ctl00$ctl02$ctl00$ctl02></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl03','')">Name</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" originalAttribute="href" originalPath="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl03','')">Name</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl04','')">Date of Birth</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" originalAttribute="href" originalPath="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl04','')">Date of Birth</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl05','')">Sex</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" originalAttribute="href" originalPath="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl05','')">Sex</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl06','')">Address</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" originalAttribute="href" originalPath="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl06','')">Address</A></TH>
<TH class=GridHeader_Office2007 style="WHITE-SPACE: nowrap" scope=col><A title="Click here to sort" href="javascript:__doPostBack('SelectedRespondents$ctl00$ctl02$ctl00$ctl07','')">City</A></TH>
<TH class=GridHeader_Office2007 style="WHIT…

I have also tried this link with no success.
http://www.telerik.com/community/forums/thread/b311D-baedtd.aspx

I know this should be fairly straightforward. 

Thanks in advance,
Curtis

0
Sebastian
Telerik team
answered on 27 Jun 2008, 03:07 PM
Hi Curtis,

It seems that you are referring to the version of the help article concerning RadGrid Classic. I suggest you review the ASP.NET AJAX equivalent of the resource and try it in your project to see whether this produces the desired effect.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
C5 Insight
Top achievements
Rank 1
answered on 27 Jun 2008, 03:18 PM
Stephen,


Great response time; thanks for setting me straight.  This worked like a charm.

Now for my "real" challenge:

Ultimately I want users to be able to click (selecting) various cells across various rows.  We can call this app a data merge application, where 5 rows might be in the grid, and the user selects the 'best' data across all 5 rows (1 unique selected cell per column), to build the best record to keep.  Hope this makes sense.

My thought was to change the color of selected cells for visual notification to the user, but also when they click "submit" and post this data, I would use the class or color of the selected cells to retrieve the actual selected data.  Will this even work?  Is this the best approach to my challenge?  I'd basically like to take the selected cells and store in variables upon posting.

Thanks in advance,
Curtis
0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2008, 07:26 AM
Hello Curtis,

You can access the selected items in the grid by using the ColumnUniqueName. Try out the following code snippet.

CS:
protected void Submit_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            string strtxt = item["ColumnUniqueName"].Text; 
            // change the BackColour of the cell; 
            item["ColumnUniqueName"].BackColor = System.Drawing.Color.Red; 
        } 
    } 

On clicking the Submit button outside the Grid, the code shown above loops through the selected items.

Thanks
Shinu.
 
Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
C5 Insight
Top achievements
Rank 1
Sebastian
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or