how to link selected value of a dropdownlist to right field?

B

Ben

Hi,

i defined a dropdownlist in a detailsview but the values are provided
programmatically. This works.
The default mod of the detailsview is INSERT.
My problem is that the selected value of the user is not inserted in the
table. What i don't know is how to link the selected value to the right
field?

With a normal field, i use something
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("myfield")
%>'></asp:TextBox>

But with a dropdownlist?
Thanks for help.
Ben


Here my code:

aspx
----
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
InsertCommand="INSERT INTO [mytable] ([datbegin]) VALUES
(@datbegin)">
<InsertParameters>
<asp:parameter Name="datbegin" Type="Integer" />
</InsertParameters>
</asp:SqlDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" >
<Fields>
<asp:TemplateField HeaderText="datbegin">
<InsertItemTemplate>
<asp:DropDownList ID="begdat" runat="server" DataTextField="datbegin" >
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

code-behind
-----------

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
'here the code to find the dropdownlist in the template and to
fill it with values
' this works so i didn't show the code here
'....
end sub
 
B

Ben

i found it:

SelectedValue='<%# Bind("datbegin") %>'



Ben said:
Hi,

i defined a dropdownlist in a detailsview but the values are provided
programmatically. This works.
The default mod of the detailsview is INSERT.
My problem is that the selected value of the user is not inserted in the
table. What i don't know is how to link the selected value to the right
field?

With a normal field, i use something
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("myfield")
%>'></asp:TextBox>

But with a dropdownlist?
Thanks for help.
Ben


Here my code:

aspx
----
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
InsertCommand="INSERT INTO [mytable] ([datbegin]) VALUES
(@datbegin)">
<InsertParameters>
<asp:parameter Name="datbegin" Type="Integer" />
</InsertParameters>
</asp:SqlDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert" >
<Fields>
<asp:TemplateField HeaderText="datbegin">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

code-behind
-----------

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
'here the code to find the dropdownlist in the template and to
fill it with values
' this works so i didn't show the code here
'....
end sub
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top