Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

c# - How to hide randomly generated row of gridview

HI coder i have a gridview in which data comes from database.. now id of all row is same what i want it to show only first row of my gridview and hide rest of the others but not their value i just wana hide them. i want their value because i have a lightbox on it.

this is my code:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
        AutoGenerateColumns="False" PageSize="1" PersistedSelection="true" 
    DatakeyNames="pptId,Priority">
        <Columns>

            <asp:TemplateField HeaderText="pptId" Visible="false">
                <ItemTemplate>
                    <asp:Label ID="lblpptId" runat="server" Text='<%# Bind("pptId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>    
          <asp:TemplateField HeaderText="Priority" Visible="false">
                <ItemTemplate>
                    <asp:Label ID="lblPriority" runat="server" Text='<%# Bind("Priority") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="View PPT">
                <ItemTemplate>
                    <a id="imageLink" href='<%# Eval("Imageurl") %>' title='<%#Eval("Description") %>'
                        rel="lightbox[Brussels]" runat="server">Start PPT</a>
                </ItemTemplate>
            </asp:TemplateField>                
        </Columns>
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
         </asp:GridView>

EDIT::

protected void Page_Load(object sender, EventArgs e)
{
    BindModule();

}
protected void BindModule()
{
    try
    {
        con.Open();
        string id = Request.QueryString["pptId"].ToString();
        //Query to get Imagesurl and Description from database
        SqlCommand command = new SqlCommand("select * from Image_Master where pptId='" + id + "' and IsEnable='True' order by Priority", con);
        dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(command);
        da.Fill(dt);          
        GridView1.DataSource = dt;
        GridView1.DataBind();                      
        GridView1.Dispose();
    }
    catch (Exception ex)
    {
        Response.Write("Error occured : " + ex.Message.ToString());
    }
    finally
    {
        con.Close();
    }
}

in the above code pptId is same for each row, my images show inside my gridview what i want is to show only first images and hide rest of other but not their values..

how to i do that.....thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think it's what you are looking for :

for(int i = 1; i < GridView1.Rows.Count; i++)
{
    GridView1.Rows[i].Visible = false;
}

Use it after binding datasource to GridView1 in code behind.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...