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

Posted on 2012-08-28
Last Modified: 2013-01-28

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

Question by:Saroj13
    LVL 53

    Accepted Solution

    Tip/Trick: Show Header and Footer of GridView when no Data returned.

    Solution: Show Header/Footer of Gridview with Empty Data Source
    LVL 53

    Expert Comment

    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

    Author Comment

    i dont want to change the row color. i want to change the color of linbutton text on linkbutton click.

    plz send code,
    LVL 19

    Expert Comment

    by:Amandeep Singh Bhullar
    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".
    LVL 53

    Expert Comment

    I did answer at least on of his questions (1 and 2) .... I don't kwow the answer for the other ones
    LVL 53

    Expert Comment

    3) Accept one or more Expert posts as the answer: ID: 38344367

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now