Problem in accessing other fields of a given row

Last post 11-19-2008 8:38 AM by sonu. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-17-2008 5:30 AM

    Problem in accessing other fields of a given row

     Hi

    In row created event of gridview control on my page I am doing something like this :-

    var

    imgViewCallBack = Function.createCallback(imgView_onclick, rowIndex);

    var

    imgView= row.findControl("imgView");

    $addHandler(imgView,

    Finally in the code

    "click", imgViewCallBack);

    // Function to handle the click event of View Image

    function

    {

    // here i have the row index and using this i can get the key field for that particulatr row

    imgView_onclick(evt , rowIndex)

    }

    but apart from the datakey fields I also want to access some other data for a given row

    I tried following code given in the ajax data controls website :-

    var index = 3;
    var item = adcControl.get_items()[index];
    item.findControl("your control");

    but it is not working .

    basically how can i access a given row when I have rowindex with me .

  •  Advertisement

    Featured Advertisement

     
  • 11-17-2008 8:13 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Problem in accessing other fields of a given row

    This should help.

    function loopItems()
    {
      var rows = grid.get_rows();
      for (var row in rows)
      {
        var dataItem = row.get_dataItem();
      }
    }

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 11-18-2008 9:30 PM In reply to

    Re: Problem in accessing other fields of a given row

     Hello Sonu

    Thanks for your reply !! But I have seen this sample code given in one of your blog site .I am not sure how the above peice of code will help me because with this I need to iterate through all the rows of the gridview .

    What I am actually looking for is if I have rowIndex with me then how can I access all the fields for that given row . I have used other code mentioned again in one of your blog site :-

    var index = 3;

    var items = adcControl.get_items()[index];

    items.findControl("Your Control");

    I am wondering why this code doesnt work with gridview wherein for index I can pass rowIndex (index of currently selected row) .

  • 11-18-2008 9:38 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Problem in accessing other fields of a given row

    I think this is better.

    var rows = grid.get_rows();
    var myRow = rows[index];   //<-- Pass your index here.
    var item = myRow.get_dataItem();

    Let me know if this helps.

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 11-18-2008 10:29 PM In reply to

    Re: Problem in accessing other fields of a given row

     Hello Sonu,

    Thank you very much . The above three lines of code solved a big problem for me and infact now i have the item object which contains all the information for a given row  so accessing any elements in that row is just a peice of cake .

     

     

     

     

     

    var  rows = gridView.get_rows();

     

     

    var  myRow = rows[rowIndex];

     

     

    var  items = myRow.get_dataItem();

    alert(items[

    "StdID"]); // Similarly user can access all the other fields for a given row Yes

    Thanks again !!!

  • 11-19-2008 8:38 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Problem in accessing other fields of a given row

    Great to see that this solved the problem.

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
Page 1 of 1 (6 items)