Solved

dropdownlist in gridview selected item

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

827 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