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>
<aspropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
AppendDataBoundItems="false">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
Enabled="false" AppendDataBoundItems="false">
</aspropDownList>
</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>
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>
<aspropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
AppendDataBoundItems="false">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="ddlTypeID" runat="server"
DataSourceID="SqltlkpBoardType"
SelectedValue='<%# Bind("PosTypeID") %>'
DataTextField="MemberType"
DataValueField="TypeID" Width="250px"
Enabled="false" AppendDataBoundItems="false">
</aspropDownList>
</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>