Solved

dropdownlist in gridview selected item

Posted on 2014-02-18
1
430 Views
Last Modified: 2014-02-18
it is working good,  BUT..   when i change BoundField DataField="servdisk"  Visible to False it is stop  working?  how to solve?


     <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView3_RowDataBound" >
            <Columns>
                <asp:BoundField DataField="driveD" HeaderText=" Drive " />
                <asp:BoundField DataField="file_id" HeaderText="Order" />
                <asp:BoundField DataField="type" HeaderText="type" />
                <asp:BoundField DataField="current_file_location" HeaderText="Path" />
                <asp:BoundField DataField="size" HeaderText="File Size" />
                <asp:BoundField DataField="sizeAF" HeaderText="Size After" />
                <asp:BoundField DataField="servdisk" HeaderText="servdisk" Visible="True" />
                <asp:TemplateField HeaderText="Server Disk">
                    <ItemTemplate><asp:DropDownList ID="servedisk_new" runat="server" Width="100px"/></ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>





    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            var ddl = (DropDownList)e.Row.FindControl("servedisk_new");
            ddl.DataSource = GetServDriveSize(DestServDropD.SelectedItem.Text, 0, 0, 2); ;
            ddl.DataTextField = "DiskName";
            ddl.DataValueField = "DiskName";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("Choos Drive", "0"));

           string seltxt= Convert.ToString(e.Row.Cells[6].Text);


            ddl.SelectedValue = seltxt;
        }



    }
0
Comment
Question by:center1010
1 Comment
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 39868255
If you set Visible="False", the BoundField isn't rendered, so you can't find it.
There are many different ways for what you are trying to do:
1: Add a HiddenField to the same TemplateField as your dropdown. Find that field instead like:
HiddenField hf= e.Row.Find("HiddenField1") as HiddenField;
if(hf!=null)
   ddl.SelectedValue = hf.Value;

Open in new window

2: Another way is use DataKeys
3: You can try setting DropDownList's  SelectedValue='<%#Eval("servdisk")%>' in the markup.
4: You can get the value from DataItem in the RowDataBound like:
DataRowView drv = e.Row.DataItem as DataRowView;
ddl.SelectedValue = drv["servdisk"].ToString();

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

9 Experts available now in Live!

Get 1:1 Help Now