Solved

dropdownlist in gridview selected item

Posted on 2014-02-18
1
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 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