I created two GridViews: Members and Sponsors
respectively and provided a total count
of these two groups of people. My problem is I have two buttons which open in Excel: MemSpreadshtBTN (Member) and SPSpreadshtBTN (Sponsor) and I could not figure out how to get the count just for Members and the other just for Sponsors in Excel format. Please help.
ASPX
<asp:Label ID="totalCountLBL" runat="server" Text="Total Count:" Visible="false"></asp:Label> <asp:Button
ID="MemSpreadshtBTN" runat="server" OnClick="MemSpreadshtBTN_OnClick" Text="Member Spreadsheet" Visible="false" /> <asp:Button
ID="SPSpreadshtBTN" runat="server" OnClick="SPSpreadshtBTN_OnClick" Text="Sponsor Spreadsheet" Visible="false" /><br />
<asp:GridView ID="GridView1"...>
...
<asp:GridView ID="GridView2"...>
...
C#
protected void TotalCount()
{
conn.Open();
try
{
string strTotalCt = "SELECT count(ConferenceRegistrationID) FROM ConferenceRegistration cr, Conference con WHERE con.ConferenceID=cr.ConferenceIDNum AND con.ConferenceID=@confID AND cr.Deleted='N'";
SqlCommand ChkTotal = new SqlCommand(strTotalCt, conn);
ChkTotal.Parameters.AddWithValue("@confID", conferenceDDL.SelectedValue);
int temp = Convert.ToInt32(ChkTotal.ExecuteScalar().ToString());
if (temp > 0)
{
totalCountLBL.Text = "<strong>Total Count:" + temp + "</strong>";
totalCountLBL.Visible = true;
MemSpreadshtBTN.Visible = true;
SPSpreadshtBTN.Visible = true;
returnLBL.Text = "<div style='margin-top: 10px;'><a href='~/Admin/Participants.aspx' onclick='window.history.go(-1); return false;'>Return to previous page</a>.</div>";
returnLBL.Visible = true;
}
else
{
ChkOther();
}
}
finally
{
conn.Close();
}
}
protected void MemSpreadshtBTN_OnClick(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ParticipantsSpreadsheet.xls");
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
htmlWrite.Write(totalCountLBL.Text.ToString() + "<br />");
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
protected void SPSpreadshtBTN_OnClick(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ParticipantsSpreadsheet.xls");
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
htmlWrite.Write(totalCountLBL.Text.ToString() + "<br />");
GridView2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}