fill two droplist

F

Frank Dulk

As I do to fill out two droplist of different tables in the event open of
the webforms.

I get to fill out one, but when I try two says that cannot open another
connection.
 
G

Gaurav Vaish \(EduJini.IN\)

Can you provide some more details....
Is there any exception? The stacktrace and, preferably also, the code.
 
F

Frank Dulk

That is the code that I am sweating for filling out the dropdownlist1 with
the records of the table1.
How do I do to fill out other dropdownlist2 with the records of another
table2?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

Dim strSql As String

Dim conexao As OleDbConnection

Dim dscmd As OleDbDataAdapter

Dim ds As DataSet

conexao = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data
source=C:\Inetpub\wwwroot\Database_acesso1\talao.mdb;")

conexao.Open()

Try

strSql = "select distinct tplt_desc from TblTipoLente order by tplt_desc"

dscmd = New OleDbDataAdapter(strSql, conexao)

ds = New DataSet

dscmd.Fill(ds, "TblTipoLente")

Me.DropCategorias.DataTextField = "tplt_desc"

Me.DropCategorias.DataValueField = "tplt_desc"

Me.DropCategorias.DataSource = ds.Tables("TblTipoLente").DefaultView

Me.DropCategorias.DataBind()

Me.DropCategorias.Items.Insert(0, New ListItem("Selecione seu tipo de
lente...", ""))

Finally

conexao.Close()

End Try

End If

End Sub

End Class
 
G

Gaurav Vaish \(EduJini.IN\)

That is the code that I am sweating for filling out the dropdownlist1 with
the records of the table1.
How do I do to fill out other dropdownlist2 with the records of another
table2?

Exactly the same way as you did for ddl1.
You need to have a new instance of OldDbConnection. The same connection will
not work.



--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
 
J

jmbledsoe

I've been using a tool called the DataSet Toolkit to handle Fills and
Updates of multiple DataTables like you're doing. It will manage your
connection for you so you don't need to worry about creating a new one,
and it will even write the SQL to fill your table at runtime, so you
won't need to do that either. You can find it here:

http://www.hydrussoftware.com

John B.
http://johnsbraindump.blogspot.com
 
F

Frank Dulk

ok Gaurav Vaish, will test in your way.
Thank you very much John B. will also see that program.

Does he/she/you have how in the dropdownlist to show the name and does keep
the id in the table, as if it was two columns?
 
G

Gaurav Vaish \(EduJini.IN\)

Hi Frank,
Does he/she/you have how in the dropdownlist
to show the name and does keep the id in the table, as if it was two
columns?

Probably couldn't understand your question.
Here's my understanding:

Table1: id, name
DropDownList:
DisplayText => name
Value => id

eg:

<option value='1'>Gaurav Vaish</option>
where 1 is the value of the field id and "Gaurav Vaish" is the value of
the field name.

That should be trivial.
ddl.DataTextField = "name";
ddl.DataValueField = "id";


--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
 
F

Frank Dulk

Exactly that.
Thank you very much.

would have as in a text box to type +1 or -1 or +74 or...
but would have to impose a limit up to +170 or -170

But has to have that mask.+ or -
 
G

Gaurav Vaish \(EduJini.IN\)

F

Frank Dulk

Everything well, I am going trying to seek something that helps me.

I am in I await .
Thank you.
 
G

Gaurav Vaish \(www.EduJini.IN\)

Frank,

Here's what you can start with...

<input id='box1' type='text' onchange='validateValue(this)'
onkeypress='return checkKey(this, event)' ... />

JavaScript initialization of the text box (for last validated value):
var box1 = getElementById('box1');
box1.validValue = -1; //Initial value

Javascript functions:

function checkKey(sender, e)
{
// Use this if you want to validate each key-press
// Return true if you accept the character typed, false if you don't
want to be accepted
return true;
}

function validateValue(tb)
{
var value = tb.value;
var setVal = tb.validValue; // The last stored valid value
try
{
var intval = int.Parse(value);
if(intval >= -170 && intval <= 170)
{
setVal = intval;
}
} catch { }
tb.validValue = setVal; // This is for internal use
tb.value = setVal; // This is what keeps changing as
user types
}

For exact and advanved javascript, you may like to go to flashy places
like www.dynamicdrive.com etc.
 
F

Frank Dulk

Does excuse, but where do I glue that code?
My knowledge is very limited.


Gaurav Vaish (www.EduJini.IN) said:
Frank,

Here's what you can start with...

<input id='box1' type='text' onchange='validateValue(this)'
onkeypress='return checkKey(this, event)' ... />

JavaScript initialization of the text box (for last validated value):
var box1 = getElementById('box1');
box1.validValue = -1; //Initial value

Javascript functions:

function checkKey(sender, e)
{
// Use this if you want to validate each key-press
// Return true if you accept the character typed, false if you
don't want to be accepted
return true;
}

function validateValue(tb)
{
var value = tb.value;
var setVal = tb.validValue; // The last stored valid value
try
{
var intval = int.Parse(value);
if(intval >= -170 && intval <= 170)
{
setVal = intval;
}
} catch { }
tb.validValue = setVal; // This is for internal use
tb.value = setVal; // This is what keeps changing as
user types
}

For exact and advanved javascript, you may like to go to flashy places
like www.dynamicdrive.com etc.
 
F

Frank Dulk

I tried to copy and to glue in the it paginates for testing and gave
mistake.
Excuse, but I didn't get.
 
G

Gaurav Vaish \(www.EduJini.IN\)

Hi Frank,
Excuse, but I didn't get.

Do a thorough study on HTML elements and events.

If you still don't get, mail me (my email is in From header, remove the
"nospam" parts)... but do study thoroughly for at least a couple of days.

That would help you in the long run as well. It's actually very simple
to study than to write a whole specific code for it. :)


--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://webservices.edujini.in
-------------------
 
F

Frank Dulk

I am going of the a glance yes. I really need.

But if wants me it orders a small page example I am thanked.
 
F

Frank Dulk

I don't have idea of how to work with scripts. A small sample page in vb.net
would be an initial point.
 
G

Gaurav Vaish \(www.EduJini.IN\)

I don't have idea of how to work with scripts. A small sample page in
vb.net would be an initial point.

I'll try to see if I can manage some time out for the help for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top