Showing posts with label drop. Show all posts
Showing posts with label drop. Show all posts

Monday, March 26, 2012

OK , my dumb question for the day

i have a drop down list fill using the following code:
If IsPostBack Then
'Put user code to initialize the page here
' create a sqlconnection
Dim cnn As SqlConnection = New SqlConnection("Data
Source=localhost;Initial catalog=Northwind;" & _
"Integrated Security=SSPI")
'create a sql command
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = "SELECT * FROM Suppliers"
' Set up the DataAdapter and fill the dataset
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As Suppliers = New Suppliers
da.Fill(ds, "Suppliers")
Dim suppROW As Suppliers.SuppliersRow
For Each suppROW In ds.Suppliers
Me.ddlData.Items.Add(suppROW.SupplierID & suppROW.CompanyName)
Next
i want to set the text of the drop down to companyname
and the value to the supplierID. What am i missing?
thanks
kesHi Kes,
You need to bind the dataset to the dropdown.
Replace this:

> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next
With this:
da.Fill(ds, "Suppliers")
ddlData.DataTextField = "CompanyName"
ddlData.DataValueField = "SupplierID"
ddlData.DataSource = dsSuppliers
ddlData.DataBind()
I'm assuming that your Suppliers object is derived from Dataset in the
example above. Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> i have a drop down list fill using the following code:
> If IsPostBack Then
> 'Put user code to initialize the page here
> ' create a sqlconnection
> Dim cnn As SqlConnection = New SqlConnection("Data
> Source=localhost;Initial catalog=Northwind;" & _
> "Integrated Security=SSPI")
> 'create a sql command
> Dim cmd As SqlCommand = cnn.CreateCommand
> cmd.CommandType = Data.CommandType.Text
> cmd.CommandText = "SELECT * FROM Suppliers"
> ' Set up the DataAdapter and fill the dataset
> Dim da As SqlDataAdapter = New SqlDataAdapter
> da.SelectCommand = cmd
> Dim ds As Suppliers = New Suppliers
> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next
> i want to set the text of the drop down to companyname
> and the value to the supplierID. What am i missing?
> thanks
> kes
and I knew that!!
I'm working through a book and i got brain lock on this
thanks
kes
"Ken Dopierala Jr." wrote:

> Hi Kes,
> You need to bind the dataset to the dropdown.
> Replace this:
>
> suppROW.CompanyName)
> With this:
> da.Fill(ds, "Suppliers")
> ddlData.DataTextField = "CompanyName"
> ddlData.DataValueField = "SupplierID"
> ddlData.DataSource = dsSuppliers
> ddlData.DataBind()
> I'm assuming that your Suppliers object is derived from Dataset in the
> example above. Good luck! Ken.
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
> "WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
> news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> suppROW.CompanyName)
>
>

OK , my dumb question for the day

i have a drop down list fill using the following code:
If IsPostBack Then
'Put user code to initialize the page here
' create a sqlconnection
Dim cnn As SqlConnection = New SqlConnection("Data
Source=localhost;Initial catalog=Northwind;" & _
"Integrated Security=SSPI")
'create a sql command
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = "SELECT * FROM Suppliers"
' Set up the DataAdapter and fill the dataset
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As Suppliers = New Suppliers
da.Fill(ds, "Suppliers")
Dim suppROW As Suppliers.SuppliersRow
For Each suppROW In ds.Suppliers
Me.ddlData.Items.Add(suppROW.SupplierID & suppROW.CompanyName)
Next

i want to set the text of the drop down to companyname
and the value to the supplierID. What am i missing?
thanks
kesHi Kes,

You need to bind the dataset to the dropdown.

Replace this:

> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next

With this:

da.Fill(ds, "Suppliers")
ddlData.DataTextField = "CompanyName"
ddlData.DataValueField = "SupplierID"
ddlData.DataSource = dsSuppliers
ddlData.DataBind()

I'm assuming that your Suppliers object is derived from Dataset in the
example above. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> i have a drop down list fill using the following code:
> If IsPostBack Then
> 'Put user code to initialize the page here
> ' create a sqlconnection
> Dim cnn As SqlConnection = New SqlConnection("Data
> Source=localhost;Initial catalog=Northwind;" & _
> "Integrated Security=SSPI")
> 'create a sql command
> Dim cmd As SqlCommand = cnn.CreateCommand
> cmd.CommandType = Data.CommandType.Text
> cmd.CommandText = "SELECT * FROM Suppliers"
> ' Set up the DataAdapter and fill the dataset
> Dim da As SqlDataAdapter = New SqlDataAdapter
> da.SelectCommand = cmd
> Dim ds As Suppliers = New Suppliers
> da.Fill(ds, "Suppliers")
> Dim suppROW As Suppliers.SuppliersRow
> For Each suppROW In ds.Suppliers
> Me.ddlData.Items.Add(suppROW.SupplierID &
suppROW.CompanyName)
> Next
> i want to set the text of the drop down to companyname
> and the value to the supplierID. What am i missing?
> thanks
> kes
and I knew that!!
I'm working through a book and i got brain lock on this
thanks
kes
"Ken Dopierala Jr." wrote:

> Hi Kes,
> You need to bind the dataset to the dropdown.
> Replace this:
> > da.Fill(ds, "Suppliers")
> > Dim suppROW As Suppliers.SuppliersRow
> > For Each suppROW In ds.Suppliers
> > Me.ddlData.Items.Add(suppROW.SupplierID &
> suppROW.CompanyName)
> > Next
> With this:
> da.Fill(ds, "Suppliers")
> ddlData.DataTextField = "CompanyName"
> ddlData.DataValueField = "SupplierID"
> ddlData.DataSource = dsSuppliers
> ddlData.DataBind()
> I'm assuming that your Suppliers object is derived from Dataset in the
> example above. Good luck! Ken.
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
> "WebBuilder451" <WebBuilder451@.discussions.microsoft.com> wrote in message
> news:AB8DDAD7-DBE8-4093-BD3D-C91677304F3F@.microsoft.com...
> > i have a drop down list fill using the following code:
> > If IsPostBack Then
> > 'Put user code to initialize the page here
> > ' create a sqlconnection
> > Dim cnn As SqlConnection = New SqlConnection("Data
> > Source=localhost;Initial catalog=Northwind;" & _
> > "Integrated Security=SSPI")
> > 'create a sql command
> > Dim cmd As SqlCommand = cnn.CreateCommand
> > cmd.CommandType = Data.CommandType.Text
> > cmd.CommandText = "SELECT * FROM Suppliers"
> > ' Set up the DataAdapter and fill the dataset
> > Dim da As SqlDataAdapter = New SqlDataAdapter
> > da.SelectCommand = cmd
> > Dim ds As Suppliers = New Suppliers
> > da.Fill(ds, "Suppliers")
> > Dim suppROW As Suppliers.SuppliersRow
> > For Each suppROW In ds.Suppliers
> > Me.ddlData.Items.Add(suppROW.SupplierID &
> suppROW.CompanyName)
> > Next
> > i want to set the text of the drop down to companyname
> > and the value to the supplierID. What am i missing?
> > thanks
> > kes
>

ok im stumped been trying to figure ou thow i can do this for a couple hours

ive got a drop down list that gets populated at the click of a button , it gets populated with the columns in any table name from my data base that i put into the text box... well my first thing i fixed that i thought would be a problem was if i hit the button twice itd populate the drop down twice and have duplicate veiwing ... so i added in a foreach to delete the code but the problem is it only runs through and deletes the column name from the table that id type into the box leaving the columns form the last table i typed in there.
heres the code

private void Button2_Click(object sender, System.EventArgs e)
{
SqlConnection rate;
SqlDataAdapter Selct;
string db;

rate = new SqlConnection( @dotnet.itags.org."xoxo");
rate.Open();
db = TextBox5.Text;
Selct = new SqlDataAdapter( "Select * From " + db, rate );
DataSet ds = new DataSet();
Selct.Fill(ds, db);
foreach (DataColumn dsc in ds.Tables[0].Columns)
{
DropDownList2.Items.Remove(dsc.ColumnName);
DropDownList2a.Items.Remove(dsc.ColumnName);
DropDownList2b.Items.Remove(dsc.ColumnName);
DropDownList2c.Items.Remove(dsc.ColumnName);
DropDownList2d.Items.Remove(dsc.ColumnName);
}

foreach (DataColumn dsc in ds.Tables[0].Columns)
{

DropDownList2.Items.Add(dsc.ColumnName);
DropDownList2a.Items.Add(dsc.ColumnName);
DropDownList2b.Items.Add(dsc.ColumnName);
DropDownList2c.Items.Add(dsc.ColumnName);
DropDownList2d.Items.Add(dsc.ColumnName);

}
}Try to use DataBind() method instead of looping.
And, you can remove the data in DropDownList with setting it null.

Try below

SqlConnection con = new SqlConnection("connectionstring");
DataTable dt = new DataTable();
string query ="select [TextString],[ValueString] from [table]";
SqlDataAdapter da = new SqlDataAdapter(query,con);

//set column names
ddlSample.DataTextField = "TextString"; //will be shown in the list
ddlSample.DataValueField = "ValueString";
// won't be shown but value for each item of the list
// DropDownList has Key/Value pair data structure.

con.open();
da.Fill(dt);
con.close();

ddlSample.DataSource = dt.DefaultView;
ddlSample.DataBind();
// I think that if dropdownlist got databound, the dropdownlist automatically reset.

If you want to make sure to reset the dropdownlist,
ddlSample = new DropDownList();

before databinding.
sorry im having trouble getting this to work and understanding how this would work
it took me a lot of trial and error plus thinking to make use of what i already had and i came up with using an invisible textbox lol like this

private void Button2_Click(object sender, System.EventArgs e)
{
SqlConnection Con = new SqlConnection( System.Configuration.ConfigurationSettings.AppSettings["PubsString"]);
Con.Open();
string TxtBx = TextBox5.Text;
string TxtBx1 = Dupe.Text;
SqlDataAdapter DtAdapt = new SqlDataAdapter( "Select * From " + TxtBx, Con );
DataSet ds = new DataSet();
DtAdapt.Fill(ds,TxtBx);
foreach (DataColumn dsc in ds.Tables[0].Columns)
{
DropDownList2.Items.Add(dsc.ColumnName);
DropDownList2a.Items.Add(dsc.ColumnName);
DropDownList2b.Items.Add(dsc.ColumnName);
DropDownList2c.Items.Add(dsc.ColumnName);
DropDownList2d.Items.Add(dsc.ColumnName);
}

if (TxtBx1 != " ")
{
SqlDataAdapter DtAdapt1 = new SqlDataAdapter( "Select * From " + TxtBx1, Con );
DtAdapt1.Fill(ds,TxtBx1);
foreach (DataColumn dsc in ds.Tables[0].Columns)
{
DropDownList2.Items.Remove(dsc.ColumnName);
DropDownList2a.Items.Remove(dsc.ColumnName);
DropDownList2b.Items.Remove(dsc.ColumnName);
DropDownList2c.Items.Remove(dsc.ColumnName);
DropDownList2d.Items.Remove(dsc.ColumnName);
}
}
Dupe.Text = TxtBx;
}

Feel free to critisize and help me find any other ways of doing this...
i suppose i could learn to close my connection
I could be wrong but isn't there a .Clear() method for you to use instead of looping over the items and removing them?
ya it works i just have to adjust a few things to get my application functional with that...
but righ tnow im just trying to figure out the difference between my program before i saved it and closed vs.net and now that ive opened it because now its not running right... i noticed it changed some events that were associated with button clicks... but still at that it needs something else

Friday, March 16, 2012

On Mouse over , Change the value of textbox in asp.net 2.0

On Mouse Over of the Button control, I want to change the value of the textbox or Drop down list value in asp.net 2.0, How to do this ?

Suresh

Well, the mouseOver is a clientside event, and ASP.Net is Serverside... so unless you postback you cant.

You can add a ClientSide event to populate the controls, but that will be all javascript events/methods/functions


Hi:

It is a client-side issue. Try this:

<input value="hello" ID="T1" onmouseover="ChangeText('anything')"/></form>


<script type="text/javascript">
function ChangeText(s){
document.getElementById("T1").value=s;
}
</script>

You can learn more about JS here

http://www.w3schools.com/js/js_popup.asp

Regards