Я создал два GridViews: Members and Sponsors
соответственно и предоставил total count
этих двух групп людей. Моя проблема в том, что у меня есть две кнопки, которые открываются в Excel: MemSpreadshtBTN (Member) и SPSpreadshtBTN (Спонсор), и я не мог понять, как получить счет только для членов, а другой только для спонсоров в формате Excel. Пожалуйста помоги.Отдельный подсчет для двух групп
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 [email protected] 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();
}
, какая часть кода не работает you.Btnclicks или выполнить скаляр, чтобы получить отсчет от select statement – user2526236
@ user2526236: Все работает, за исключением небольшой порции. Предположим, на моей странице общее количество 10 человек. 6 из них являются Членами и 4 являются Спонсорами. Как я могу подсчитать количество 6 человек в электронной таблице участников, и число из 4 отображается в электронной таблице Спонсора? –
В таблице ConferenceRegistration в вашей БД есть столбец, который отличает спонсора или участников. Есть ли столбец, по которому вы можете отличить, является ли он спонсором или членом? – user2526236