在CommonClass.cs文件上引发错误错误:当前上下文中不存在 [英] Error raising on CommonClass.cs file Error: doesnt exist in current context
本文介绍了在CommonClass.cs文件上引发错误错误:当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<pre lang="cs">
<strong>CommonClass.cs</strong> Error raising on this page
Error: The name 'gvwBoarding' doesnot exist in current context.
<strong>BusRouterHeader.aspx.cs</strong>
gvwBoarding is a Gridview id in BusRouterHeader.aspx.cs page
protected void btnSave_Click(object sender, EventArgs e)
{
string re = "Given Field is Empty";
if (ddlBusTravelsName.SelectedIndex.ToString() != "0" && txtAmount.Text != "" && txtFromCity.Text != "" && txtToCity.Text != "" && txtDepartureTime.Text != "" && txtArrivelTime.Text != "")
{
DoFill();
string res = CC.DoInsertBusRHeader(B);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + res + "');", true);
Clear();
<strong>CC.DoGdviewBoarding(); //I will call this method...... </strong>
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + re + "');", true);
}
}
<strong>CommonClass.cs</strong>
public void DoGdviewBoarding()
{
SqlCommand cmd;
try
{
SqlDataAdapter sda;
DataSet ds;
mDbconnection = conn.GetDefaultDbConnectionString();
cmd = new SqlCommand("[DBO].[Proc_GetBoarding]", mDbconnection);
cmd.CommandType = CommandType.StoredProcedure;
sda = new SqlDataAdapter(cmd);
ds = new DataSet();
sda.Fill(ds, "BusRouterHeaderMaster");
gvwBoarding.DataSource = ds;
gvwBoarding.DataBind();
mDbconnection.Close();
}
catch (Exception e)
{
}
finally
{
if (cmd != null)
cmd.Dispose();
cmd = null;
mDbconnection.Close();
}
}
</pre>
< big>< / big>
推荐答案
嘿,
如果您准备更改代码,将 DoGdviewBoarding()修改为返回数据表的内容。
Hey,
If you are ready to change your code, modify your DoGdviewBoarding() to something like this which returns a data table.
public DataTable DoGdviewBoarding()
{
//line of codes
}
并在您的代码中使用
and in your code use
gvwBoarding.DataSource = DoGdviewBoarding();
这篇关于在CommonClass.cs文件上引发错误错误:当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文