Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting selected values from form problem 1

Status
Not open for further replies.
Nov 29, 2001
72
0
0
US
Guys,
I'm still sort of new to .NET. I am having problems being able to get selected values from one of my forms. All I get are the original values and not any changes that may have been made.

I have tried everything I can think of from completely redoing the form from scratch to creating a new project using just that one form all with the same results.

Here's the code snippet where I am pulling off the values:

recID = txtReqNo.Text
recDate = txtDate.SelectedDate
AAID = ddlAdmin.SelectedValue
DocID = ddlPhysician.SelectedValue
reason = txtReason.Text
Status = ddlStatus.SelectedValue
comments = txtComment.Text
delete = ddlDelete.SelectedValue

Seems rather basic doesn't it? I have done maybe 2 dozen similar type forms with no problems, but for some reason here I can only get the original values and not any that have been changed.

I am totally out of ideas. I can't believe I'm stuck on this issue and have been for about 8 hours. I'm about ready to pull my hair out or pour myself a drink or both :)

If someone could even point me in the right direction or give me something else to look at, it would be much appreciated.

Thanks in advance for your help,
Dave
 
First off, make sure in page_load you have...
Code:
Sub Page_Load(sender As Object, e As EventArgs)
    If Not Page.IsPostBack Then
        BindMyDropDownList1()
        BindMyDropDownList2()
        ....
    End If
End Sub

Then, your strings need to be...
delete = ddlDelete.SelectedItem.Value
or
delete = ddlDelete.SelectedItem.Text

IF...
you have set your DataTextField="myField" and DataValueField="myFieldID", you can pull one or the other.
The value is the item not displayed in the DDL.

If this is inside a datagrid, i have more for you, if not, this will work.
 
adamroof,
I was just getting ready to blow the form away again and recreate and debug it one text box or DDL at a time. I wouldn't have gotten any different results, although I may have left work early for the bar :)

You were absolutely right, I had not databound my DDLs or text boxes. Once I did, it worked fine.

Thanks for your help and for helping me right before I wasted the rest of my day, I salute you with a purple star.

Thanks again,
Dave
 
no prob,
when i was starting off, i was crying, kicking and screaming with the DDLs and getting values from them. Inside a datagrid is another can of worms.
Glad to save time.

another trick is to add value not in the table dataset...
Sub BindDDL()
...after DDL DataBind() and connection.Close()
myDDL.Items.Insert(0, new ListItem("Select One", 0))
End Sub

then, you can say...

if myDDL.SelectedItem.Value = 0 Then
message.text = "You must select something"
exit sub
else
'Make something else happen
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top