Search
Tuesday, March 09, 2010 ..:: Home ::.. Register  Login
 .NET Links Minimize

 Print   
 My Links Minimize

 Print   
 Recent Blog Entries Minimize
Mar 12

Written by: Wil Dobson
3/12/2008 8:05 AM

You are unable to bind the selected value of your dropdownlist to your GridViews datasource BECAUSE your dropdownlist has its OWN datasource which it is bound do. 

The solution I came up with was to have a hidden textbox in the cell along with the dropdownlist. This is simply a asp:TextBox with the visible property marked as false. The hidden textbox is bound to the appropriate field in the GridView's datasource.  The DropDownList is bound to its own DataSource.  Good so far?  Here is the SOURCE code for my two controls..

< asp:TextBox ID="UBER_USER_CONTROL_IDTextBox" runat="server" 
     Text='<%# Bind("UBER_USER_CONTROL_ID", "{0}") %>'
     Visible="False" Width="60px">< /asp:TextBox>

< asp:DropDownList ID="ddlEditUserControlNames"
     runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="sdsUserControlNames"
     DataTextField="USER_CONTROL_NAME" DataValueField="UBER_USER_CONTROL_ID" OnDataBound="ddlEditUserControlNames_DataBound"
     OnSelectedIndexChanged="ddlEditUserControlNames_SelectedIndexChanged">
     < asp:ListItem Selected="True" Value="0">Select An Uber Control< /asp:ListItem>
< /asp:DropDownList>

 When a user selects a value in the DropDownList, a method is called OnSelectedIndexChanged="ddlEditUserControlNames_SelectedIndexChanged">

This method sets the value of the hidden textbox for me. Here is the code I use to access the controls within my gridview (or formview in this case):
 

// ddl edit events
    protected void ddlEditApplicationNames_SelectedIndexChanged(object sender, EventArgs e)
    {
        // APPLICATION_IDTextBox
        TextBox txtAppId = (TextBox)fvEditUberApps.FindControl("APPLICATION_IDTextBox");
        DropDownList ddl = (DropDownList)sender;
        txtAppId.Text = ddl.SelectedValue;
    }

 The other trick to this, is ensuring the initially selected value of the dropdownlist matches the value in the hidden textbox... I do that by using the event which populated my dropdownlist to begin with... this way:

protected void ddlEditApplicationNames_DataBound(object sender, EventArgs e)
    {
        
  

Copyright ©2008 Wil Dobson

Tags:

  
 PS: Minimize

 Print   
 Sponsors Minimize

Get your own Komets drinking Stein!

Get your KOMETS gear!
Proceeds go for player awards @ the end of each season.

  Quality Geek Gear from GeeksWithGuns.com

We use DiscountASP!! Click to join up!


 Print   
 Facebook Minimize

Wil Dobson's Facebook profile


 Print   
 Blogs Minimize

 Print   
 Manage Blog Minimize
You must be logged in and have permission to create or edit a blog.

 Print   
 Blog Archives Minimize

 Print   
Copyright 2008 by Wil Dobson   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2010 by DotNetNuke Corporation