Accessing gridview DataKey field in some javascript function

Last post 11-10-2008 10:29 AM by xxxd. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-07-2008 10:03 PM

    Accessing gridview DataKey field in some javascript function

    Hi

    I have just started to use the ajax data control and no doubt they are fabulous . But I am having difficulty in using then since there is no predefined library or api wherein I can refer and get some help .

    For eg. I want to access the datakey field of a given row in some javascript function which is not related with gridview event . All the examples given in this site use e.get_row() etc kind of syntax but in my case there is no event argument like 'e' since I am trying to access it outside . Rather I have access to some other control in that same row . So is it possible to get the data Key of a given row of gridView control when you have control on some other control in the same row.

    Also the client side syntax for working with ADC are again very difficult to remember or to find. I have to switch between the examples to find out what next .

  •  Advertisement

    Featured Advertisement

     
  • 11-09-2008 6:30 AM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Slacker
    • Points 17,720

    Re: Accessing gridview DataKey field in some javascript function

     http://www.codeplex.com/AjaxDataControls/Release/ProjectReleases.aspx?ReleaseId=8312

    On the download page, there is API help, there you can find some documentation.

    As for accessing datakeys, yes you can accessing it through all predefined events of the controls, those events, such as ItemDataCreated, ItemDataBound are not really tied to any client side events.

    Please feel free to post your specific questions, I will help you work out.

     

  • 11-10-2008 1:26 AM In reply to

    Re: Accessing gridview DataKey field in some javascript function

     Hi

    Thanks for your words .

    Actually my problem for accessing the datakey field is solved . I went through the verious post of this forum and in one place I found a sample given by you on how to work with RowCreated()event of the gridview control .

    I have two things to ask you :-

    1.) I am using web services to retrive data from database and then I am binding it to grid . Now asp.net ajax by default uses json format for data exchange . Will json fail in serializing and deserializing the data if I try to record which is of type uniqueidentifier .

    2.) I am following the samples given in the codeplex site for understanding how ajaxdatacontrols work . Examples given for gridview control which include pagination has a peice of code something like this :-

    if ((list.Count == 0) || (total == 0))
            {
                return null;
            }

            PagedResult<Employee> result = new PagedResult<Employee>();

            result.Rows = list;
            result.Total = total;       

    return

    result;

    where list contains the record returned from database . Now if there is no record the returned value is null . So when I tried to bind it to the gridview control in my aspx page ie


    pager.set_recordCount(result.Total);
    gridView.set_dataSource(result.Rows);
    gridView.dataBind();

    I was getting error saying Total is either undefined or null .

    what i did was as a fix rather than returning null i simply returned result object inside if block .

    I dont know whether I have overlooked something but I will appreciate if you can let me know what was the main reason behind returning null and also if in some case we have to return null how it will be handled in aspx page while databinding .

  • 11-10-2008 10:29 AM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Slacker
    • Points 17,720

    Re: Accessing gridview DataKey field in some javascript function

     thanks.

    If you want to return DataTables from your webservice or pageMethods you will also need to declare the following converters:

    <jsonSerialization maxJsonLength="4194304">
      <converters>
        <add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/>
        <add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/>
        <add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/>
      </converters>
    </jsonSerialization>

    as blogged by Sonu:

    http://dotnetslackers.com/Community/blogs/sonukapoor/archive/2008/06/24/ajaxdatacontrols-adc-faq-how-to-get-started-with-the-ajaxdatacontrols-and-visual-studio-2008.aspx

    As for returning 0 records / or null, to me, it is basically the same, sure, you can change the data service, as in

            PagedResult<Employee> result = new PagedResult<Employee>();

            result.Rows = list;
            result.Total = list.Count;       

    Remember, these are just sample code, you have the power to code your own. 

Page 1 of 1 (4 items)