1

I'm using a GridView and Details View and my datasource is a custom ObjectDataSource that returns a DataSet.

This isn't a SQL server, I'm using an LDAP query to get users from Active Directory.

I have two custom datasources in the ASPX page with one bound to the GridView and one to the DetailsView. They both have SelectMethods and Parameters that work.

The GridView works perfectly. When I run the query against the Active Directory, I get my list of people in the GridView with an autogenerated select link. I can click on this link and it passes whichever value I want via the DataKeyNames to the SelectedIndexChanged event.

What I'm doing in this event is setting the parameter for the ObjectDataSource for the DetailsView control. It does call into the custom class and return back a DataSet that contains ONE USER.

What's interesting here is that when I setup this ObjectDataSource in the ASPX page, I give it a Default parameter value. When the page loads, the DetailsView control shows up with the values returned via the default parameter.

So...I know this works to some degree.

However, when I set the parameter in the SelectedIndexChanged event for the GridView, the select method in the custom class runs and returns the proper DataSet, but the DetailsView control is not updated with the new information.

Here's the ASPX code for ObjectDataSource for the DetailsView:

<asp:ObjectDataSource ID="_prvODSDetailsView" 
                  SelectMethod="_pubGetSingleUserDataSetByKerberosID"
                  TypeName="NotImportant"
                  runat="server">
   <SelectParameters>
  <asp:Parameter Direction="Input" Name="param_KerberosID" Type="String" DefaultValue="somedefaultvalue" />
   </SelectParameters>
</asp:ObjectDataSource>  

Here's my DetailsView code:

<asp:DetailsView ID="_prvDetailsViewShown" 
          CssClass="detailgrid"
          GridLines="None"
          DefaultMode="Edit"
          EmptyDataText="<No Details Available>"
          AutoGenerateRows="true"
          DataKeyNames="KerberosID"
          DataSourceID="_prvODSDetailsView"
          Width="100%"
          runat="server">
</asp:DetailsView>

Just to reiterate. This works on the first page load using the default value from the parameter.

void _prvGridView_SelectedIndexChanged( object sender, EventArgs e )
{
    DataKey k = _prvGridView.SelectedDataKey;
    string kerberosID = k.Value.ToString();
    Parameter parameter = new Parameter( "param_KerberosID", TypeCode.String, kerberosID );
    _prvODSDetailsView.SelectParameters[ 0 ] = parameter;
}

What I'm expecting to happen is the binding occurs and the control gets automatically updated. In fact, I'm pretty sure the DetailsView binding does occur, but the control never gets updated.

What am I missing?

1 Answer 1

1

Well, I found the answer. My GridView is in an UpdatePanel (ASP .NET AJAX) and the DetailsView as not. Apparently, you can't have that.

When removed all of the AJAX components, it worked.

When I put the DetailsView in the SAME UpdatePanel as the GridView, it also worked.

1
  • 1
    It also works if its in another UpdatePanel with the UpdateMode set to Conditional and you do an Update() in the code-behind for the DetailsView UpdatePanel when you do a select in the gridview.
    – Dan7el
    Nov 8, 2010 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.