Expand|Select|Wrap|Line Numbers
- <InsertItemTemplate>
- <div class="insertArea">
- <asp:DropDownList ID="lstUser" runat="server" DataSourceID="UserDataSource" DataTextField="UserName" DataValueField="UserId" SelectedValue='<%# Bind("UserId") %>' AppendDataBoundItems="true"></asp:DropDownList>
- <asp:TextBox ID="txtPhone" runat="server" MaxLength="20" Width="150" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
- <asp:TextBox ID="txtEmail" runat="server" MaxLength="255" Width="400" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
- <asp:Button ID="cmdAdd" runat="server" Text="Add" CommandName="insert" />
- </div>
- </InsertItemTemplate>
The bizarre thing about this is that the exact same code works fine in the EditItemTemplate. As far as I know, I need to bind the UserId so that it gets fed into the UserId parameter in the objectdatasource. If I remove the SelectedValue='<%# Bind("UserId") %>' part then I no longer get the error, but the objectdatasource tries to pass null for the userid to the database, which is of no use.
Here is the insert section of the objectdatasource for reference:
Expand|Select|Wrap|Line Numbers
- <InsertParameters>
- <asp:ControlParameter Name="Company" ControlID="lstCompany" PropertyName="SelectedValue" Type="Int32" />
- <asp:Parameter Name="UserId" Type="Object" />
- <asp:Parameter Name="Sequence" Type="Int32" />
- <asp:Parameter Name="ContactPhone" Type="String" />
- <asp:Parameter Name="ContactEmail" Type="String" />
- </InsertParameters>
Regards,
Mark