How to access GridBoundColumn by DataField?

3 posts, 0 answers
  1. Alexander
    Alexander avatar
    152 posts
    Member since:
    Jun 2012

    Posted 14 Nov 2012 Link to this post

    I need to update one row of RadGrid after ajax call.
    I get correct dataItem by rowIndex:
    var dataItem = $find("<%= MyGrid.ClientID %>").get_masterTableView().get_dataItems()[radGridRowIndex];

    But then it's a total mess!
    I have tried a lot of ways to get correct cell to update its value, but in vain:
    <telerik:GridBoundColumn HeaderStyle-CssClass='GridHeaderGreen la gridBottomHeaderGreen' ItemStyle-CssClass='la' DataField="CounterName" HeaderText="Performance counter" />

    dataItem["CounterName"]
    dataItem.get_dataItem()["CounterName"]
    dataItem.CounterName
    dataItem.get_dataItem().CounterName

    I have also tried to use UniqueColumn name = DataField and apply get_cell method, but also in vain.

    I can use GridTemplateColumn instead, but it will generate more markup (will add span inside td), I wanted to avoid this.

    p.s. Had to use UniqueColumnName everywhere. And did
    $($find("<%= MyGrid.ClientID %>").get_masterTableView().getCellByColumnUniqueName(dataItem, "CounterName")).text(bla-bla-bla);
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 14 Nov 2012 Link to this post

    Hello,

    If you do not give Uniquename then it take datafield name as uniquename.

    var grid = $find("<%=RadGrid1.ClientID %>");
                  grid.get_masterTableView().get_dataItems()[0].get_cell("Name").innerHTML = "Your text";


    <Columns>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                        </telerik:GridBoundColumn>
                         
                    </Columns>

    ////if you have multiple column which have same DataField

    var grid = $find("<%=RadGrid1.ClientID %>");
    // Access column which have Name as Datafield
                    grid.get_masterTableView().get_dataItems()[0].get_cell("Name").innerHTML = "Your text for first column"
     
    // if you have multiple column which have same DataField then add 1,2,3....... after datafield name
     
                    grid.get_masterTableView().get_dataItems()[0].get_cell("Name1").innerHTML = "your text for second column"


    <Columns>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                        </telerik:GridBoundColumn>
                          <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                        </telerik:GridBoundColumn>
     
                    </Columns>


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexander
    Alexander avatar
    152 posts
    Member since:
    Jun 2012

    Posted 21 Nov 2012 Link to this post

    Thanks. Although by unique column name it looks more neat :) So i will stick to it...
Back to Top