GridView DropDownList

Hi ,

I'm tring to make one of my fields in the gridview to become a ddl. The collecion is small and fixed and I can add it manualy (no need of datasource). but I'd like to display the text part of the ddl and save to record the value part, and also I'd like to display the setectedItem text on databind

Can anybody help?

nuritatAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
In normal mode, you have

<asp:Label ID="Label3" runat="server" Text='<%# Bind("Grp") %>'></asp:Label>

which is binding to the code. Now the trouble is that the description is probably in another table right?

You would have to modify your select query to include that description and then

<asp:Label ID="Label3" runat="server" Text='<%# Bind("StaffType") %>'></asp:Label>
0
 
sarabhaiCommented:
Please put  your  gridview code and ddl value-text pairs.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nuritatAuthor Commented:
Thanks,

 the third article did help but still when displaying the grid view not in edit mode I get the fields code and not the description text (= ddl.selecteditem.text)

How can I resolve this

Thanks
0
 
nuritatAuthor Commented:
this is the code:

 <asp:TemplateField HeaderText="¿¿¿" SortExpression="BackGround_he">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Columns="30" Rows="3"
                        Text='<%# Bind("BackGround_he") %>' TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("BackGround_he") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="¿¿¿¿¿" SortExpression="Grp">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Grp") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataSourceID="AccessDataSource2" DataTextField="StaffType"
                        DataValueField="StaffTypeID" SelectedValue='<%# Bind("Grp") %>' >
                    </asp:DropDownList>
                </EditItemTemplate>

            </asp:TemplateField>
           
0
 
CodeCruiserCommented:
>but still when displaying the grid view not in edit mode
You have label when not in edit mode. The DDL only shows in edit mode right?
0
 
nuritatAuthor Commented:
Yes, thats what I wanted

not in edit mode I wanted to view the code's description and not the code

in Edit mode it works fine

0
 
nuritatAuthor Commented:
Sorry for the delay... too much work ..

anyway Thanks, it works
0
 
CodeCruiserCommented:
Glad to help :-)
0
All Courses

From novice to tech pro — start learning today.