Adding a DropDownList entry during edit

D

David C

I have a editable GridView with only a few data fields on it. One of the
data fields is bound to a DropDownList column named PosTypeID. The DropDown
is getting values from a selection table. I want to be able to add a new
entry to the selection table and then place that new entry into the row
being edited. I have an SqlDataSource tied to the DropDown that uses a
SELECT...UNION SELECT command to give me all valid selections and a 0 (for
those with no selection) and a -1 (for adding a new selection). Below is my
GridView and SqlDataSource for the DropDown. Any guideance is appreciated.

David

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="PositionID"
DataSourceID="SqlDataSource1" EmptyDataText="There are no data
records to display."
GridLines="Vertical" onrowdeleting="GridView1_RowDeleting"
onrowupdating="GridView1_RowUpdating">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:CommandField ShowEditButton="True" >
<ItemStyle Width="60px" ForeColor="DarkGreen" />
</asp:CommandField>
<asp:BoundField DataField="PositionID"
HeaderText="PositionID" ReadOnly="True" SortExpression="PositionID"
Visible="false" />
<asp:TemplateField HeaderText="Position"
SortExpression="Position">
<EditItemTemplate>
<asp:TextBox ID="txtPosition" runat="server"
Text='<%# Bind("Position") %>' MaxLength="100" Width="500px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblPosition" runat="server" Text='<%#
Bind("Position") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Position Type"
SortExpression="PosTypeID">
<EditItemTemplate>
<asp:DropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
AppendDataBoundItems="false">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
Enabled="false" AppendDataBoundItems="false">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" >
<ItemStyle Width="60px" ForeColor="Red" />
</asp:CommandField>
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>

<asp:SqlDataSource ID="SqltlkpBoardType" runat="server"
ConnectionString="<%$ ConnectionStrings:FiledataConnectionString %>"
SelectCommand="SELECT 0 As TypeID, NULL As MemberType UNION
SELECT -1 As TypeID, N'<<Add New>>' As MemberType UNION SELECT [TypeID],
[MemberType] FROM [tlkpBoardType] ORDER BY [MemberType]">
</asp:SqlDataSource>
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top