Solved

How to assign selected value to dropDownList inside gridview?

Posted on 2008-10-16
3
932 Views
Last Modified: 2008-10-19
hi all,
i have a grid view which include a drop down list, when every time i pull out data from database, i want to assign the value to that dropdownlist.

i like to do something like this:
if(ds.Tables[0].Rows[0].ItemArray[1].ToString() != "")
{
      ddlRvStatus.selectedValue = ds.Tables[0].Rows[0].ItemArray[1].ToString() ;
}

how to do that?
thanks
<asp:GridView ID="gvReview" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" OnRowDataBound="gvReview_RowDataBound">

                <HeaderStyle CssClass=data_title />

                <Columns>

                                        <asp:TemplateField HeaderText="Review Status">

                        <ItemTemplate>

                            <asp:DropDownList ID="ddlRvStatus" runat="server" CssClass="field_item_width">

                            <asp:ListItem Value="Complete">Complete</asp:ListItem>

                            <asp:ListItem Value="Escalated">Escalated</asp:ListItem>

                            <asp:ListItem Value="Incomplete">Incomplete</asp:ListItem>

                            </asp:DropDownList>

                        </ItemTemplate>

                    </asp:TemplateField>

                                    </Columns>

                </asp:GridView>
 
 

****************************************

In .cs file:

DataSet dsReview = new DataSet();

dataAdapter.Fill(dsReview);

gvReview.DataSource = ds;

gvReview.DataBind(); // when bind the dataSet, i want to assign selected value(which is in dataset) to that dropdroplist, how to do that?

Open in new window

0
Comment
Question by:viola123
3 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 22738187
In the gridView_RowDataBound Event
u'll have to find the ddl using findcontrol

protected void gvStationery_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        try

        {

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                    DropDownList ddlRvStatus = e.Row.FindCOntrol("ddlRvStatus") as DropDownList;
 

ddlRvStatus.Items.FindByValue(ds.Tables[0].Rows[0].ItemArray[1].ToString()).Selected = true;

                            

            }

        }

Open in new window

0
 
LVL 1

Expert Comment

by:josgal
ID: 22738718
Just assign or get the value of the cell, as if it was a "text" cell.
.NET, knowing is a comboBox (or dropDownList) will assign the value to its content (in this case, the combo)

0
 
LVL 6

Author Comment

by:viola123
ID: 22753938
informaniac,
thanks a lot, it works
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now