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

  • Thread starter Thread starter Ben
  • Start date Start date
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
 
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
 
Back
Top