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

How to access radgrid rows from a button?

8 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sreedhar ambati
Top achievements
Rank 1
sreedhar ambati asked on 19 Aug 2009, 06:20 AM
Hi

I am having a radgrid and a server button outside the radgrid.
In dotnet grid and button I can able to access the grid rows from button client side click.

Is it possible in Telerik ?
If so please provide me some example code.

Regards
Sreedhar A

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Aug 2009, 06:42 AM
Hi Sreedhar,

I have found a help document for asp.net RadGrid which says that the Rows collection is available only when specific client features/events related to grid rows are enabled.
Rows

Shinu
0
sreedhar ambati
Top achievements
Rank 1
answered on 19 Aug 2009, 08:21 AM
Thanks I set and it is working.


 

var grid = window["<%= gvWorkingHours_New.ClientID %>"];

 

Now    grid.MasterTableView   is not coming as null

 


But if I am using this

var grid = $find('<%= gvWorkingHours_New.ClientID %>').get_masterTableView();

it is coming as null.

We are using older version of Telerik. ie 2008

I cannot upgrade to Telerik 2009. Product is already in live.

I want to access all rows and cells of the grid in javascript
Can you please tell me the next steps of this 

var grid = window["<%= gvWorkingHours_New.ClientID %>"];

 

 

grid.MasterTableView  

 


.....
Please send me some code.

Thanks
Sreedhar

 

 

 

0
sreedhar ambati
Top achievements
Rank 1
answered on 19 Aug 2009, 09:15 AM

 Hi

I am having a radgrid. It is having one templatecolumn . I assigned a uniquename for that gridtemplate column.
I am having a button outside the grid
On clientclick of that button I am accessing all the rows of the grid.
I could able to read all the rows but in the cellID.innerHTML I am getting 

"<INPUT class=inputsNoExpression id=ctl00_Cont_gvWorkingHours_New_ctl01_ctl04_txtSlotName value=Sree name=ctl00$Cont$gvWorkingHours_New$ctl01$ctl04$txtSlotName> "

My value is Sree
How to get that?

Please give the code snippet for accessing the gridtemplate cell value.

My Code:



<asp:Content ID="content" runat="server" ContentPlaceHolderID="Cont">
 
            function AddSlot_New()
            {
                debugger;
                var grid = window["<%= gvWorkingHours_New.ClientID %>"];
         
                 for (var i = 0; i < grid.MasterTableView.Rows.length; i++)  
                 {  
                     var row   = grid.MasterTableView.Rows[i]; 
                     var cellID = grid.MasterTableView.GetCellByColumnUniqueName(row, "txtSlotName");    
                     alert(cellID.innerHTML);
                  }

            }

<rad:RadGrid ID="gvWorkingHours_New" runat="server" Skin="Default" AutoGenerateColumns="false"
             OnNeedDataSource="gvWorkingHours_New_NeedDataSource"  OnItemDeleted="gvWorkingHours_New_ItemDeleted">
               <ClientSettings>
                <Selecting AllowRowSelect="true" />
               </ClientSettings>
                <MasterTableView>
              
                    <Columns>
                   
                        <rad:GridTemplateColumn UniqueName="txtSlotName">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="txtSlotName" CssClass="inputsNoExpression" Text='<%# Bind("SlotName") %>'></asp:TextBox>
                            </ItemTemplate>
                        </rad:GridTemplateColumn>

</Columns>
                </MasterTableView>
            </rad:RadGrid>
         
       <asp:Button ID="LinkButton1" runat="server" width="97px" CssClass="sf-inputsLinkButton" OnClientClick="return AddSlot_New()" OnClick="LinkButton1_Click"/>
      

 </asp:Content>


Regards
Sreedhar Ambati

0
vivek
Top achievements
Rank 1
answered on 02 Nov 2010, 10:46 AM
I am having GridButtonColumn on my RadGrid. If i click a row,I want to get cell values of the row .
Please let me know how do i achieve this.

Thanks in Advance
Vivek
0
Princy
Top achievements
Rank 2
answered on 02 Nov 2010, 12:25 PM
Hello Vivek,

Attach CommandName to the GridButtonColumn and in ItemCommand event, check with the CommandName and can access the corresponding cell value.

ASPX:
<telerik:GridButtonColumn CommandName="Click" Text="Click"></telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == "Click")
       {
          GridDataItem item = (GridDataItem)e.Item;
          string v = item["ColumnUniqueName"].Text;
       }
   }

Thanks,
Princy.
0
vivek
Top achievements
Rank 1
answered on 03 Nov 2010, 05:33 AM

Hey Princy,

 

Thanx .. It works!

0
vivek
Top achievements
Rank 1
answered on 03 Nov 2010, 06:03 AM

Need one more favor from your side.
 I need  to create a search page. There are several search criteria. Once i filled the first criteria, there should be button for NEXT to fill next criteria. It looks likes a grid where criteria are inside the grid and simple paging is there for NEXT and PREVIOUS.

Could you please suggest me how do i take list controls and dropdowns inside the grid .How do i appear new controls after clicking NEXT or you will suggest new approach ?

 

Thanks in advance.

0
Vasil
Telerik team
answered on 03 Nov 2010, 12:26 PM
Hello vivek,

It will be way more simple if you just use one RadListBox1 and two buttons. On these buttons click you can change the datasource of your RadListBox.

For example, if your asp page look like:
<telerik:RadListBox ID="RadListBox1" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Prev" OnClick="Button2_Click" />
<asp:Button ID="Button1" runat="server" Text="Next" OnClick="Button1_Click" />

This will be the pseudocode for the code-behind:
protected void Button1_Click(object sender, EventArgs e)
{
    string selectedValue = RadListBox1.SelectedItem.Value;
    Session["criteriaNumber"] = (Session["criteriaNumber"] as int) + 1;
    (Session["criteriaSelecteds"] as List<string>).Add(selectedValue);
 
    RadListBox1.DataSource = new YourDataSource(Session["criteriaNumber"], selectedValue);
    RadListBox1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
    int num = Session["criteriaNumber"] as int;
    Session["criteriaNumber"] = num - 1;
    (Session["criteriaSelecteds"] as List<string>).RemoveAt(num);
    string selectedValue = (Session["criteriaSelecteds"] as List<string>)[num - 1];
    RadListBox1.DataSource = new YourDataSource(num - 1, selectedValue);
    RadListBox1.DataBind();
}

The above pseudocode only illustrates how you can achieve similar functionality. You will have to implement it depending on your exact scenario.

Regards,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
sreedhar ambati
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
sreedhar ambati
Top achievements
Rank 1
vivek
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or