deed02392
deed02392

Reputation: 5022

Add a 'placeholder' row in a GridView

I want to allow users to go through a set of tables, first creating a row in one table, then creating a row that is inserted with the previous row as a key.

Because the subsequent GridViews have no data until their previous rows are entered, the HTML for the table isn't rendered.

I want to add a placeholder row to ensure that the GridViews are always present with just an example row saying something like 'No data added yet'.

Is this possible? Perhaps a dummy row added programatically rather than being a feature of the control?

Thanks.

Upvotes: 0

Views: 1777

Answers (2)

Orkun
Orkun

Reputation: 7248

A dummy row worked for me in a similar case.

            DataRow dr = mDataTable.NewRow();
            dr["KEY"] = "DUMMY";
            mDataTable.Rows.Add(dr);

            DataView pView = new DataView(mDataTable);
            gridView.DataSource = pView;
            gridView.DataBind();

            gridView.Rows[0].CssClass = "Hidden"; //I am not sure about this actually, see the result

You can try this as an alternative, if other solutions donT work.

Upvotes: 0

Icarus
Icarus

Reputation: 63972

Use the EmptyDataTemplate property of the GridView:

<asp:gridview id="CustomersGridView" 
    datasourceid="CustomersSqlDataSource" 
    autogeneratecolumns="true"
    runat="server">
    <emptydatarowstyle backcolor="LightBlue"
      forecolor="Red"/>
    <emptydatatemplate>
      <asp:image id="NoDataImage"
        imageurl="~/images/Image.jpg"
        alternatetext="No Image" 
        runat="server"/>
        No Data Found.  
    </emptydatatemplate> 
  </asp:gridview>

Upvotes: 2

Related Questions