Go Back   Velocity Reviews > Newsgroups > DotNet
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

DotNet - dropdownlist value into detailsview: how?

 
Thread Tools Search this Thread
Old 06-28-2006, 08:04 AM   #1
Default dropdownlist value into detailsview: how?


Hi,

I have still this unsolved problem, so i post it again.
I hope someone replies and solves this or tells me it's impossible to do
that this way ...
My feeling is that it must work ...

I have a detailsview for inserting data, and a dropdownlist which
selectedValue must be used to fill one of the field of the detailsview.
Table 'pc' is related to table 'lok'.

I tried a lot of things, but still without succes. Here are the two methods
i tried with two different errors. It works only when i introduce directly a
value in "DefaultValue" (see below)

Thanks for help


1) first method:
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
...
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asparameter Name="na" Type="String" />
<asparameter Name="ty" Type="String" />
</InsertParameters>
....
Code-behind:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
SqlDataSource1.InsertParameters.Add("lok", lokl)
End Sub

This gives: No value given for one or more required parameters
----------------------------------------------------------------------------
-------------------------
2) second method
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
...
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asparameter Name="na" Type="String" />
<asparameter Name="ty" Type="String" />
<asparameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
</InsertParameters>
...

Code-behind:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
End Sub

This gives: You cannot add or change a record because a related record is
required in table 'lokl'
which means in fact that the value of the parameter is not passed!

It works when i give directly a value: <asparameter Name="lok"
Type="String" DefaultValue="1-45" />


tartuffe2
tartuffe2 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump