• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1903
  • Last Modified:

How Gridview having no rows display header and one empty row using c# and asp.net


I have gridview having two columns script title and script text.
1. If datareader is having no rows, how to display gridview header with one empty row in asp.net and c#?
2. If gridview is having no rows, display detailsview header also with one empty row.
3. If gridview script title linkbutton is selected, how to change the forecolor of selected title?

          <table style="width:210%;" >
            <tr style="vertical-align:top;">
            <td style="border:0px solid #000; width:200px;">
             <asp:GridView ID="ScriptsGridView" runat="server" CellPadding="1" CellSpacing="1" 
                    HeaderStyle-CssClass="nodrag nodrop" AutoGenerateColumns="False"  
                    HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#F28B13" 
                    style="position: relative; top: -52px; left: 322px;"            
                     Height="100%" Width="102%"  DataKeyNames="ScriptID" 
                    BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1pt" 
                    <HeaderStyle CssClass="nodrag nodrop" BackColor="#43816E" BorderColor="White" BorderStyle="Solid" BorderWidth="1px"  Font-Bold="true"  ForeColor="White"></HeaderStyle>

                   <RowStyle Height="20px" />
                             <asp:TemplateField HeaderText="Script Name">  
              <asp:linkbutton ID="TitleLinkButton" runat="server" Text='<%# Eval("Title") %>' CommandName="Select" />

        <td id ="details" style="position: relative; top: -52px; left: 322px; width:60%; border-bottom-style:solid 1pt; border-right-style:solid 1pt; border-color:#cccccc; " runat="server"  >
        <asp:DetailsView ID="DetailsView1" runat="server"  Height="100%" Width="100%" BorderStyle="None" BorderColor="#ffffff"   FieldHeaderStyle-BorderStyle="None" 
            AutoGenerateRows="False"  DataSourceID="SomeOtherSqlDataSource" HeaderText="ScriptText"
             HeaderStyle-CssClass="nodrag nodrop">
              <HeaderStyle Height="33px" HorizontalAlign="Center" BackColor="#43816E" BorderColor="#cccccc" BorderStyle="Solid" BorderWidth="1px"  Font-Bold="true"  ForeColor="White"></HeaderStyle>

                   <RowStyle Height="20px" />

              <asp:TemplateField ItemStyle-BorderStyle="None" HeaderStyle-HorizontalAlign="Center">
                  <asp:Label ID="DetailLabel" runat="server" Text='<%# Eval("ScriptTextPlain") %>' BorderStyle="None"  />
                  <HeaderStyle Font-Bold="True" />



          ID="SomeOtherSqlDataSource" runat="server" 
          ConnectionString="<%$ ConnectionStrings:ScriptsConnectionString %>" 

        <asp:ControlParameter ControlID="ScriptsGridView" PropertyName="SelectedValue" Name="Script_ID" Type="Int32" DefaultValue="1" />


SqlDataReader rdr =  GetScriptsDataReader();
      if (!rdr.HasRows)
           ScriptsGridView.DataSource = rdr;


Open in new window

  • 4
1 Solution
Tip/Trick: Show Header and Footer of GridView when no Data returned.

Solution: Show Header/Footer of Gridview with Empty Data Source
Change the color of gridview row when the row is selected..

Change gridview row color at linkbutton click which is a templated field in gridview RSS
Saroj13Author Commented:
i dont want to change the row color. i want to change the color of linbutton text on linkbutton click.

plz send code,
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Amandeep Singh BhullarCommented:
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
I did answer at least on of his questions (1 and 2) .... I don't kwow the answer for the other ones
3) Accept one or more Expert posts as the answer: ID: 38344367
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now