Solved

dropdownlist in gridview selected item

Posted on 2014-02-18
1
427 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

14 Experts available now in Live!

Get 1:1 Help Now