Hide a gridView row in asp.net

后端 未结 13 767
说谎
说谎 2021-01-14 21:22

I am creating a gridView that allows adding new rows by adding the controls necessary for the insert into the FooterTemplate, but when the Ob

相关标签:
13条回答
  • 2021-01-14 21:58

    Maybe try:

    e.Row.Height = Unit.Pixel(0);
    

    This isnt the right answer but it might work in the meantime until you get the right answer.

    0 讨论(0)
  • 2021-01-14 21:58

    Why are you not using the EmptyDataTemplate? It seems to work great even though I have only been using it for a couple days...

    0 讨论(0)
  • 2021-01-14 22:00

    You could handle the gridview's databound event and hide the dummy row. (Don't forget to assign the event property in the aspx code):

    protected void GridView1_DataBound(object sender, EventArgs e)
        {
            if (GridView1.Rows.Count == 1)
                GridView1.Rows[0].Visible = false;
        }
    
    0 讨论(0)
  • 2021-01-14 22:02

    If you do not want to display data when the column/row is null:

    if (!String.IsNullOrEmpty(item.DataName))
    {
        e.Row.Visible = false;
    }
    
    0 讨论(0)
  • 2021-01-14 22:03

    You should use DataKeyNames in your GridView:

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="FooID">

    And then retrieve it on your code: GridView1.DataKeys[0].Value.ToString()

    Where "0" is the number of the row you want to get the "FooID"

    0 讨论(0)
  • 2021-01-14 22:05

    To make it visible, just use:

    Gridview.Rows.Item(i).Attributes.Add("style", "display:block")
    

    And to make it invisible

    Gridview.Rows.Item(i).Attributes.Add("style", "display:none")
    
    0 讨论(0)
提交回复
热议问题