web stats analysis

Archive for September 2nd, 2013

How to pass variables or values from one asp vb code page to another?

Using below way to pass variables or values from one asp vb code page to another.

Using session easy way in asp.net/VB.net.
Session(“TestVariable”) = “aaaa”
From another .aspx.vb page you can now use below value. Example:
Dim str as String = “”
str = Session(“TestVariable”)
You can access this page on any of your .aspx pages for using below references .
Session(“TestVariable”).

The type or namespace name ‘Form1′ could not be found (are you missing a using directive or an assembly reference?)

Solution of The type or namespace name ‘Form1′ could not be found (are you missing a using directive or an assembly reference?)

Just add the below namespace:

using System.Windows.Forms;

How to bind data to dropdownlist in asp.net?

Try the following code in aspx page:


<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False"></asp:gridview>

Try the below code in aspx.cs page in page_load:

Add below namespace:

using System.Data.SqlClient;


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection cn = new 

SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("select * from student", cn);

cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "username";
DropDownList2.DataValueField = "userid";
cmd.Dispose();
}
}
}    

Try the below code in aspx.cs page in DropDownList click event:


protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Your 

ConnectionString name"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("select * from student where ID=@userid ", cn);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userid", DropDownList2.SelectedValue);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
cmd.Dispose();
}
}