Prev: Error: Validation of viewstate MAC failed
Next: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
From: Ben on 5 Sep 2009 13:08 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
From: Ben on 5 Sep 2009 13:19
i found it: SelectedValue='<%# Bind("datbegin") %>' "Ben" <qcqcqs(a)qcqscqc.df> schreef in bericht news:u5sQAukLKHA.1492(a)TK2MSFTNGP03.phx.gbl... > 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 > > > > |