C# 如何在asp.net上运行2个函数单击按钮
我想在RunKDF_OnClick按钮上运行两个函数,分别是displayTable()和ExportCSV(),但我只能运行函数ExportCSV()中的一个。 下面是我的代码C# 如何在asp.net上运行2个函数单击按钮,c#,asp.net,webforms,C#,Asp.net,Webforms,我想在RunKDF_OnClick按钮上运行两个函数,分别是displayTable()和ExportCSV(),但我只能运行函数ExportCSV()中的一个。 下面是我的代码 public void RunKDF_OnClick(object sender, EventArgs e) { ConnectionInfo connectionInfo = new ConnectionInfo("xx.xx.xx.xxx", xx, "root", new
public void RunKDF_OnClick(object sender, EventArgs e)
{
ConnectionInfo connectionInfo = new ConnectionInfo("xx.xx.xx.xxx", xx, "root", new
AuthenticationMethod[]
{
// Pasword based Authentication
new PasswordAuthenticationMethod("root","xxxx"),
});
using (SshClient ssh = new SshClient(connectionInfo))
{
ssh.Connect();
ssh.RunCommand("perl -w /tmp/ThermalValue/bin/kdf2csv/thermalKDF.pl");
ssh.RunCommand("exit");
ssh.Disconnect();
}
displayTable();
ExportCSV();
}
public void displayTable()
{
string connectionString = @"Data Source = xxxxx; port = xxxx; Initial Catalog = xxxx; User Id = xxxxx; password = xxxxx";
using (MySqlConnection sqlCon = new MySqlConnection(connectionString))
{
sqlCon.Open();
MySqlDataAdapter sqlDa = new MySqlDataAdapter("SELECT UID AS UNIT_ID ,Tvalue AS Temperature_Value , File AS KDF_File_Name FROM OEE_PROD.thermal", sqlCon);
DataTable table = new DataTable();
sqlDa.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}
}
//这是ExportCSV方法
public void ExportCSV()
{
字符串conn=@“数据源=xxxxx;端口=xxxx;初始目录=OEE\U产品;用户Id=xxxx;密码=xxxxx”;
使用(MySqlConnection con=newmysqlconnection(conn))
{
//这是我的用于gridview的aspx
<asp:GridView CssClass="GridView" Width="100%" ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerSettings FirstPageText="First" LastPageText="Last" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
问题在于您正在调用
Response.End
以提前结束。
结束所有当前缓冲到客户端的输出,停止执行
页面,并引发EndRequest事件
你能分享displayTable的方法吗?是的,请参考displayTable你试过通过放置断点来运行它吗?是的,我将断点放在displayTable中,但没有在我的网页中显示该表。因此调用了
displayTable
方法。sql查询是否返回任何数据?你能展示一下如何定义他gridview 1
?导出csv方法的作用是什么?
<asp:GridView CssClass="GridView" Width="100%" ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerSettings FirstPageText="First" LastPageText="Last" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>