• 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

Hi,

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" 
                    onrowcommand="ScriptsGridView_RowCommand">
                    <HeaderStyle CssClass="nodrag nodrop" BackColor="#43816E" BorderColor="White" BorderStyle="Solid" BorderWidth="1px"  Font-Bold="true"  ForeColor="White"></HeaderStyle>

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

        </Columns>
      </asp:GridView>
      </td>
      
       
        <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" />

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


              </asp:TemplateField>
              
            </Fields>

          </asp:DetailsView>

         
        </td>
      </tr> 
      </table>
         <asp:SqlDataSource 
          ID="SomeOtherSqlDataSource" runat="server" 
          ConnectionString="<%$ ConnectionStrings:ScriptsConnectionString %>" 
         SelectCommand="usp_GetScriptTextDetail_ScriptOrder"
          SelectCommandType="StoredProcedure"
          >

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

      </asp:SqlDataSource>


c#
SqlDataReader rdr =  GetScriptsDataReader();
      if (!rdr.HasRows)
      {
           ScriptsGridView.DataSource = rdr;
          ScriptsGridView.DataBind();

        }

Open in new window

0
Saroj13
Asked:
Saroj13
  • 4
1 Solution
 
DhaestCommented:
Tip/Trick: Show Header and Footer of GridView when no Data returned.
http://geekswithblogs.net/dotNETvinz/archive/2009/03/11/tiptrick-show-header-and-footer-of-gridview-when-no-data.aspx

Solution: Show Header/Footer of Gridview with Empty Data Source
http://forums.asp.net/t/960167.aspx
0
 
DhaestCommented:
Change the color of gridview row when the row is selected..
http://www.daniweb.com/web-development/aspnet/threads/202708/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
http://forums.asp.net/t/1730233.aspx/1
0
 
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,
0
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".
0
 
DhaestCommented:
I did answer at least on of his questions (1 and 2) .... I don't kwow the answer for the other ones
0
 
DhaestCommented:
3) Accept one or more Expert posts as the answer: ID: 38344367
0
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