Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<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 = &quot;Given Field is Empty&quot;;
           if (ddlBusTravelsName.SelectedIndex.ToString() != &quot;0&quot; &amp;&amp; txtAmount.Text != &quot;&quot; &amp;&amp; txtFromCity.Text != &quot;&quot; &amp;&amp; txtToCity.Text != &quot;&quot; &amp;&amp; txtDepartureTime.Text != &quot;&quot; &amp;&amp; txtArrivelTime.Text != &quot;&quot;)
           {
               DoFill();
               string res = CC.DoInsertBusRHeader(B);
               ClientScript.RegisterStartupScript(this.GetType(), &quot;myalert&quot;, &quot;alert('&quot; + res + &quot;');&quot;, true);
               Clear();
               <strong>CC.DoGdviewBoarding(); //I will call this method...... </strong>

           }
           else
           {
               ClientScript.RegisterStartupScript(this.GetType(), &quot;myalert&quot;, &quot;alert('&quot; + re + &quot;');&quot;, 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>
Posted

1 solution

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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900