Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,

since last two days I searched the entire web. but I did not get any useful code
regarding a DataGrid ComboBoxcolumn;I have a DataGrid with 4 columns,"Location"
"From" "To"and "DispatchStatus". these columns are binded to a MSAccess DataBase .but the 4 th column I want as a ComboBoxColumn,so that it gives some pre decided value such as "Dispatched" "Received" "ReturnedBack" "waiting for Delivery" in the comboboxcolumn.

regards
iqbal
Posted

 
Share this answer
 
In stead of Bound Field use Template Field for the Combob box column


<asp:TemplateField HeaderText="Example">
 <ItemTemplate>
                                                                <asp:DropDownList ID="ddExample"  AutoPostBack="false" runat="server" />
</ItemTemplate>
                                                            </asp:TemplateField>



and in .cs file write the function to get values need to listed on Drop Down 

and on gdv_RowDatabound event bind it with gridview

like this

<pre lang="c#"><pre>DropDownList ddexample = (DropDownList)e.Row.FindControl("ddExample");
                    ddexample .DataSource = options;
          ddexample .DataTextField =options.Columns["Examples"].ToString();
          ddexample .DataValueField = options.Columns["Examples"].ToString();
                    
                    ddexample .DataBind();
                    TableCell gridview= e.Row.Cells[10];
                    ddexample .SelectedValue = ddexample .Text;
 
Share this answer
 
v3
Comments
[no name] 13-Feb-12 7:06am    
in case of WPF DataGrid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900