Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When does datasource reissue a select
Message
From
20/06/2008 14:14:13
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01325539
Message ID:
01325833
Views:
18
I found the answer. See http://www.theproblemsolver.nl/dotnet_faq_0013.htm. It seems that the .NET framework has a quirk that the listbox is populated after a postback from the viewstate. Therefore if the value is not in the listbox when the postback occurs, it will not be there after the postback either. The solution is to add it explicitly before the postback occurs.

Thanks for your interest.

>What is sql += " WHERE list_members.list_id =" & Session("CurrentList").ToString
>
>And also may be data are cached?
>
>>Hi Naomi, I'm not quite sure what you are suggesting. The select statement for the datasource is not changeing, only the result because after the insert there is an additional record that meets the criteria. This is the SELECT statement.
>>
>> Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
>>        Session("CurrentList") = ListBox1.SelectedValue
>>        Dim sql As String
>>        sql = "SELECT list_members.list_id, list_members.personid, "
>>        sql += " list_members.persontag, maillist.lname, "
>>        sql += " maillist.fname + maillist.middle + maillist.lname + maillist.suffix + ', ' + maillist.company AS name"
>>        sql += " FROM list_members "
>>        sql += " LEFT JOIN maillist ON list_members.personID = maillist.personID "
>>        sql += " WHERE list_members.list_id =" & Session("CurrentList").ToString
>>        sql += " ORDER BY lname"
>>        SqlDataSource3.SelectCommand = sql
>>        lblOwner.Text = ListBox1.SelectedValue
>>    End Sub
>>
>>The user makes a choice in Listbox1 that controls the contents of Listbox3 via the above code. (Note the reset of the SelectCommand.) So I really don't need to return a value from the new record. I just need to make sure its included in the selection set.
>>
>>
>>>Can you return the SCOPE_IDENTITY() back and select the data based on it?
>>>
>>>>Hi John, Thanks for your reply. The INSERT is working OK. I have verified that. SOmeone else helped with the error on line 6. Here's my current version.
>>>>
>>>>    Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
>>>>        Dim sql As String = "INSERT into list_members (list_ID, personID) VALUES "
>>>>        sql += "(" & Session("CurrentList").ToString & "," & ListBox2.SelectedValue.ToString & ")"
>>>>        SqlDataSource3.InsertCommand = sql
>>>>        SqlDataSource3.Insert()
>>>>        SqlDataSource3.Select(DataSourceSelectArguments.Empty)
>>>>        ListBox3.DataBind()
>>>>        lblOwner.Text = sql
>>>>    End Sub
>>>>
>>>>
>>>>but I still don't see the new data unless I move to a different page and then come back.
>>>>
>>>>>Hi Don,
>>>>>
>>>>>On repost, the contents should automatically be OK assuming that the Insert was successful. Try trapping the results of the Insert to ensure that it's working.
>>>>>
>>>>>>With a .NET webpage, if a SQLDatasource is updated programmatically, when does the SELECT become reexecuted? Say there is a button that inserts a new record. When the page reposts, the contents of the listbox remain unchanged. How do we reissue the SELECT so the contents of the listbox will be updated?
>>>>>>
>>>>>>
>>>>>>    Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
>>>>>>        Dim sql As String = "INSERT into list_members (list_ID, personID) VALUES "
>>>>>>        sql += "(" & Session("CurrentList").ToString & "," & ListBox2.SelectedValue.ToString & ")"
>>>>>>        SqlDataSource3.InsertCommand = sql
>>>>>>        SqlDataSource3.Insert()
>>>>>>        SqlDataSource3.Select()       ' This line presents an error and may not belong
>>>>>>        ListBox3.DataBind()
>>>>>>    End Sub
>>>>>>
>>>>>>
>>>>>>
>>>>>>Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform