简体   繁体   English

在GridView中添加“占位符”行

[英]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. 由于后续GridView在输入之前的行之前没有数据,因此不会呈现表的HTML。

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'. 我想添加一个占位符行,以确保GridViews始终只有一个示例行,表示“尚未添加数据”。

Is this possible? 这可能吗? Perhaps a dummy row added programatically rather than being a feature of the control? 也许是以编程方式添加虚拟行而不是控件的功能?

Thanks. 谢谢。

Use the EmptyDataTemplate property of the GridView: 使用GridView的EmptyDataTemplate属性:

<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>

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. 如果其他解决方案不起作用,您可以尝试将此作为替代方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM