Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:05:53+00:00 2026-06-09T15:05:53+00:00

I am developing a simple system that has small reporting services. The reporting services

  • 0

I am developing a simple system that has small reporting services. The reporting services in general is a DropDownList and based on the value of DropDownList, a Gridview will be generated. Under this GridView there is an ImageButton for printing the GridView as a Word Document.
My problem now is: that button is appeared all the time. It should be appear with the GridView because it is related to it. So how to do that?

ASP.NET Code:

<div>

        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
            DataSourceID="SqlDataSource2" DataTextField="Title" DataValueField="ID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:PM_RegistrationSysDBConnectionString %>" 
            SelectCommand="SELECT [ID], [Title] FROM [Events]"></asp:SqlDataSource>

    </div>

    <br />

    <div>    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowFooter="true">
            <Columns>
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

                <%--<asp:TemplateField>
                    <FooterTemplate>
                        <asp:ImageButton ID="wordBtn" CssClass="icon" runat="server" ImageUrl="images/word.png" 
                           ToolTip="Generate a Word Document" OnClick="creat_word_table"></asp:ImageButton>
                    </FooterTemplate>
                </asp:TemplateField>--%>
            </Columns>
        </asp:GridView>
        <br />
        <asp:ImageButton ID="wordBtn" CssClass="icon" runat="server" ImageUrl="images/word.png" 
                           ToolTip="Generate a Word Document" OnClick="creat_word_table"></asp:ImageButton>
    </div>

C# Code:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["PM_RegistrationSysDBConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        string eventTitle = DropDownList1.SelectedItem.Text;
        string cmd = @"SELECT     dbo.Events.Title, dbo.Users.Name
                        FROM         dbo.BookingDetails INNER JOIN
                                              dbo.Events ON dbo.BookingDetails.EventID = dbo.Events.ID INNER JOIN
                                              dbo.Users ON dbo.BookingDetails.NetworkID = dbo.Users.NetworkID
                        WHERE     (dbo.Events.IsActive = 1) AND (dbo.Events.Title = '"+eventTitle+"')";
        SqlDataAdapter da = new SqlDataAdapter(cmd, conn);
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }


    public void creat_word_table(object sender, EventArgs e)
    {
        Response.AddHeader("content-disposition", "attachment;filename=Export.doc");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.word";

        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        HtmlForm frm = new HtmlForm();
        GridView1.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(GridView1);
        frm.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());
        Response.End();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:05:55+00:00Added an answer on June 9, 2026 at 3:05 pm

    try this

    by default set your image button to visible = false;

    myImageButton.Visible = false;

    then before you set the datasource of the grid you check if you have any records

    something like dt.Rows.Count

    forexample

    if(dt.Rows.Count > 0)
       myImageButon.Visible = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a simple system that has unlimited categories and items in each
I am developing a simple informative system which will use a lot of images.
I am developing a simple tool that will be used across a variety of
I am developing for a system that has an interactive telnet management console. Requirements
I'm developing an add on to a system I have that will allow my
I am currently developing a database system for a school that will work with
I'm developing a project in Symfony2(.0.x) and I'm building a simple auto login system.
I'm trying to devise a plugin system for a simple web app I'm developing.
I'm developing a control which inherits from a System.Windows.Form.Panel. The idea is very simple:
Can anyone recommend a good Java game engine for developing simple tile-based games? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.