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

Javascript in gridview

1 Answer 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anjali
Top achievements
Rank 1
Anjali asked on 18 Aug 2011, 09:27 PM
Hi All,
I am working on this task for past 2 days and could not solve this problem. I have a radgrid with a column of linkbutons inside it. when a user clicks on any link button, I pop up a javascript message based on some conditions.
ScriptManager.RegisterStartupScript(Page, this.GetType(), "message", string.Format("confirm_select('{0}','{1}');", RadGrid_IDPicker.ClientID,row.RowIndex + 1), true);

inside the function confirm_select, I have to make one row bold, the row that user clicked on and make the previous bolded row as normal/unbolded.
To achieve this, I am looping though the radgrid and unbolding all the rows and bolding the currenlty selected row if the user presses ok, but if the user pressed cancel, I would leave the previous row as bolded. below is my code
<script type="text/javascript"
var selectedRowIndex = -1;
    function confirm_select(gridViewID, rowIndex) {
        debugger;
  
  
        var gridview = document.getElementById(gridViewID);
        var master = gridViewID.get_masterTableView();
          
        if (confirm("You are leaving the parent level of the currently selected ID, are you sure?") == true) {
  
            for (var i = 1; i < gridview.rows.length; i++) {
                //not the selected row
                if (i != rowIndex)
                    gridview.rows[i].style.fontWeight = 'normal';
                //selected row
                else {
                    gridview.rows[i].style.fontWeight = 'bold';
                    selectedRowIndex = rowIndex;
                }
            }
  
        }
        else {
            if (selectedRowIndex != -1)
                gridview.rows[selectedRowIndex].style.fontWeight = 'bold';
  
        }
    }
  
</script>

I am getting an error right here

 

 

var master = gridViewID.get_masterTableView();

 


I would not have done the get get_masterTableView(), but I could not loop thorugh the gridview rows to make them bolded or unbolded. Below is the code for my gridview.
I also tried

var master = gridview.get_masterTableView();
but above line of code didn't work either.

<telerik:RadGrid ID="RadGrid_IDPicker" AllowSorting="True" PageSize="100" AllowPaging="True"
                                        runat="server" GridLines="None" OnPageIndexChanged="RadGrid_IDPicker_PageIndexChanged"
                                       OnPageSizeChanged="RadGrid_IDPicker_PageSizeChanged" Width="1500px" Visible="false" OnItemDataBound="RadGrid_IDPicker_DataBound"  >
                                        
                                       <MasterTableView RetrieveAllDataFields="true" AutoGenerateColumns="false" DataKeyNames="ID" >
                                           <Columns>
                                               <telerik:GridTemplateColumn UniqueName="TemplateLinkColumn"  AllowFiltering="false" HeaderText="ID">
                                                
                                                   <ItemTemplate>
                                                       <asp:LinkButton ID="ID_Link" runat="server" OnClick="MCLID_Link_Click" Text='<%#Bind("ID") %>' CommandName="Bold"></asp:LinkButton>
                                                     
                                                   </ItemTemplate>
                                                     
                                               </telerik:GridTemplateColumn>
                                                  <telerik:GridTemplateColumn    HeaderText="TAG">
                                                   <ItemTemplate>
                                                      <asp:Label ID="lbltag" runat="server" Text='<%#Bind("TAG") %>'></asp:Label>
                                                     
                                                   </ItemTemplate>
                                           </Columns>
                                       </MasterTableView>
                                       <PagerStyle Mode="NextPrevAndNumeric" />
                                   </telerik:RadGrid>

I don't have anything else defined. this gridview is inside the radPanelbar so the whole gridview is enclosed in this

<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Width="1500px" BackColor="#E6E6E6" ExpandMode="MultipleExpandedItems">
    <Items>
        <telerik:RadPanelItem runat="server" Text="ID Picker" Expanded="true" >
            <Items>
                <telerik:RadPanelItem Text="" Expanded="true">
                    <ItemTemplate>
                              //radgrid is right here

i am not sure what am I doing wrong, but I spend lot of hours on it and this is not working.

Any help will be highly appreciated.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 22 Aug 2011, 03:41 AM
Hello Anjali,

Try using $find() to get the RadGrid client-side object. Find more information below:
http://www.telerik.com/help/aspnet-ajax/grid-getting-client-object.html

All the best,
Iana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Anjali
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or