GSS
GSS

Reputation:

DetailsView does not appear despite visible = true, and how to bind to an empty hashtable?

I am trying to bind a hashtable to a detailsview in my ASP.NET web app. When I do this, the detailsview does not appear on the webpage when I do a debug. I have checked ALL the properties for the control and ensured that the visible and autogeneratecolumns (there is no autogeneraterows property) is set to true, and it is.

Also, I want to bind this detailsview to a hashtable, but when I do, I keep getting object reference not set to an instance of an object errors due to the datasource property or when I say datasource = strings.keys (where strings is the Id of the hashtable). I can understand why this happens, as the strings.keys property is null (hasn't been specified, even when I specify it from using an external example of how this property is used, same error). I was expecting the detailsview to just render an empty table with Key and Object rows. How could I achieve that? Eventually, I want to bind a label to a value I get back from the hashtable (using a function returning a string).

Thanks

Upvotes: 0

Views: 1110

Answers (2)

GSS
GSS

Reputation:

Ok so I've done this now:

I have a BLL class which is responsible for retrieving and adding items to the hashtable collection. One of the functions is AddToCollection(), which takes parameters for key and value. I select this method via the objectdatasource control, and make up parameter values. I still don't see the detailsview on my page though?

ASPX code:

<asp:DetailsView ID="CopyDetails" runat="server" AllowPaging="True"
                 Height="161px" Width="140px" BackColor="White"
                 AutoGenerateRows="true" BorderColor="Gray"
                 BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" 
                 Font-Size="10px">
    <PagerStyle BackColor="#00CCFF" />
</asp:DetailsView>
<br />
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
                      SelectMethod="ReturnString" TypeName="Strings">
    <SelectParameters>
        <asp:Parameter DefaultValue="Test" Name="SendFrom" Type="String" />
        <asp:Parameter DefaultValue="1" Name="StepOfSite" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

Upvotes: 1

DOK
DOK

Reputation: 32841

Could you initialize the hashtable with one element containing Key and Value of empty string? Then, you'll have an instantiated hashtable object, which can be repopulated with the selected data when the user clicks. Also, heed the event you use in the page lifecycle to instantiate the hashtable.

Upvotes: 1

Related Questions