This is a migrated thread and some comments may be shown as answers.

binding dropdownitem to grid control in normal mode

7 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zash
Top achievements
Rank 1
Zash asked on 22 Nov 2008, 12:03 AM


Hi,

I'm having some issue to bind activitydate and products in this example to bind to grid control in normal mode.Please help.Thanks







<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %> 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="system_engines_myactivity_Default" %> 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server">  
    <title>Untitled Page</title> 
</head> 
 
<script language="JavaScript">  
     
      
</script> 
<body > 
    <form id="form1" runat="server">  
    <div> 
      
    </div> 
      
      
 
      
    <telerik:RadScriptManager ID="ScriptManager5" runat="server" /> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
              
                  <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                  </UpdatedControls> 
            </telerik:AjaxSetting> 
              
              <telerik:AjaxSetting AjaxControlID="RadGrid2">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel2"/>  
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
          
        </AjaxSettings>     
      
    </telerik:RadAjaxManager> 
      
     <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="20">  
            <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /> 
     </telerik:RadAjaxLoadingPanel> 
 
        
      <asp:DropDownList ID="ddDateSpan"    
               runat="server" AutoPostBack="true" OnSelectedIndexChanged="DateSpan_SelectedIndexChanged">  
         
         
      </asp:DropDownList> 
        
      <telerik:RadGrid DataSourceID="SqlDataSource1" Skin="Vista" AllowAutomaticDeletes="true" 
            AllowAutomaticInserts="true" AllowAutomaticUpdates="true" ID="RadGrid1" runat="server"   
               OnItemCreated="RadGrid1_ItemCreated" onItemDataBound="RadGrid1_ItemDataBound"  > 
              
            <MasterTableView DataKeyNames="key" Width="100%" CommandItemDisplay="Top" 
                AutoGenerateColumns="false">  
                <Columns> 
                    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">  
                        <ItemStyle Width="50px" /> 
                    </telerik:GridEditCommandColumn> 
                      
                 
                    <telerik:GridBoundColumn UniqueName="Notes"  SortExpression="Notes" HeaderText="Task Notes" 
                            DataField="Notes"  ColumnEditorID"GridTemplateColumnEditor1"  > 
                    </telerik:GridBoundColumn> 
                      
                    <telerik:GridDropDownColumn    DataField="activity_id"  UniqueName="ActivityTypeID"   HeaderText="Activity Type" 
                             ListTextField="display" ListValueField="item_pk"  ColumnEditorID="DropDownEditor1" 
                             
                             DataSourceID="SqlDataSource_ActivityType"   > 
                     </telerik:GridDropDownColumn> 
                       
                     <telerik:GridDropDownColumn  DataField="product_id"  UniqueName="productgroup" HeaderText="Products" ListTextField="product" 
                     ListValueField="obj_id" ColumnEditorID="DropDownEditor_product"    
                      > 
                       
                     </telerik:GridDropDownColumn> 
                       
                     <telerik:GridDropDownColumn   DataField="budget_id"  UniqueName="BudgetID"   HeaderText="Budget" 
                             ListTextField="display" ListValueField="id"  ColumnEditorID="DropDownEditor2" 
                             
                             DataSourceID="SqlDataSource_Budget"  > 
                     </telerik:GridDropDownColumn> 
                       
                     <telerik:GridDropDownColumn  DataField="activitydate" UniqueName="DateID" HeaderText="Activity Date"   
                      ColumnEditorID="DropDownEditor_Date" 
                      > 
                          
                       
                     </telerik:GridDropDownColumn>   
                   
                
                    
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
          
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            UpdateCommand="update [user.multi.activity] set [Notes]=@notes,[activity_id]=@activity_id,budget_id=@budget_id ,product_id=@product_id,activitydate=@activitydate where [key]=@key" 
            InsertCommand="insert into [user.multi.activity] (Notes,activity_id,budget_id,product_id,activitydate,user_id,timespan_id) values(@Notes,@activity_id,@budget_id,@product_id,@activitydate,{0},{1})" 
               
                ConnectionString="<%$ ConnectionStrings:ConString %>"   > 
              
            <UpdateParameters> 
                <asp:Parameter Name="Notes" Type="string" /> 
                 
                <asp:Parameter  Name="activity_id" Type="Int32"  /> 
                <asp:Parameter  Name="budget_id" Type="Int32"  /> 
                <asp:Parameter  Name="product_id" Type="Int32"  /> 
                <asp:Parameter Name="activitydate" Type="String" /> 
                <asp:Parameter Name="key" Type="Int32" />                 
              
            </UpdateParameters> 
            <InsertParameters> 
                <asp:Parameter Name="Notes" Type="string" /> 
                <asp:Parameter Name="activity_id" Type="Int32"  />                
                <asp:Parameter  Name="product_id" Type="Int32"  /> 
                <asp:Parameter Name="activitydate" Type="String" /> 
                <asp:Parameter Name="timespan_id" Type="Int32" /> 
                  
            </InsertParameters> 
              
              
                 
            
           </asp:SqlDataSource> 
             
         <asp:SqlDataSource ID="SqlDataSource_ActivityType" runat="server" 
              
            SelectCommand="SELECT  item_pk,display FROM [escworks.item] where itemgroup_id=187"   
             
              ConnectionString="<%$ ConnectionStrings:ConString %>"   > 
             
          
           </asp:SqlDataSource> 
             
           <asp:SqlDataSource ID="SqlDataSource_Budget" runat="server" 
              
            SelectCommand="SELECT -1 as [id],'please choose' as [display],'-1' as [sort] UNION SELECT [budget].[obj_id] as [ID], [budget].[accountnumber] + ' ' + [budget].[description] as [display], [budget].[description] as [sort] FROM [escworks.object] [primary] INNER JOIN [budget] [budget] ON [primary].[obj_pk] = [budget].[obj_id] INNER JOIN [user.multi.budget] [user] ON [budget].[obj_id] = [user].[budget_id] WHERE (([user].[enabled] = 1) )  "   
             
             ConnectionString="<%$ ConnectionStrings:ConString %>"   > 
             
          
           </asp:SqlDataSource> 
             
            
              
              
             
            
              
                
                   
             
              
                    
             
              
                 
              
          
          
             
          
             
         
          
 
     <asp:Button ID="btnNext" runat="server" Text="Next" OnClick="GetStatus_Next">  
          
        </asp:Button> 
      <asp:Button ID="btnBack" runat="server" Text="Previous" OnClick="GetStatus_Previous" Visible=false>  
          
        </asp:Button> 
          
          
      
      
    </form> 
</body> 
</html> 

 
using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using Telerik.Web.UI;  
using System.Collections.Generic;  
using System.Collections.Specialized;  
using System.Data.SqlClient;  
 
 
public partial class system_engines_myactivity_Default : System.Web.UI.Page  
{  
 
    protected string Constring = "";  
    protected int span_id;  
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
 
        PopulateDateSpan();  
        span_id = Convert.ToInt32(ddDateSpan.SelectedItem.Value);  
        SqlDataSource1.InsertCommand = string.Format(SqlDataSource1.InsertCommand, Convert.ToInt32(escWorks.Configuration.CurrentUser.UserId.ToString()), span_id);  
 
        SqlDataSource1.SelectCommand = "SELECT  [key],activitydate,activity_id,product_id,budget_id,notes FROM [user.multi.activity] where user_id = " + escWorks.Configuration.CurrentUser.UserId.ToString() + "and timespan_id=" + span_id;  
 
 
    }  
 
    protected override void OnInit(EventArgs e)  
    {  
        base.OnInit(e);  
 
        ddDateSpan.ID = "ddDateSpan";  
 
 
        ServerConnection.ConnectionService ConObj = new ServerConnection.ConnectionService();  
        Constring = "";  
 
        InitializeComponent();  
    }  
 
    private void InitializeComponent()  
    {  
        this.RadGrid2.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(this.RadGrid2_NeedDataSource);  
        this.Load += new System.EventHandler(this.Page_Load);  
 
    }  
 
 
 
 
    protected void DateSpan_SelectedIndexChanged(object sender, System.EventArgs e)  
    {  
 
 
        RadGrid1.DataBind();  
 
 
    }  
 
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
 
        if (e.Item is GridDataItem && e.Item.IsInEditMode)  
        {  
            GridDropDownListColumnEditor list = (e.Item as GridEditableItem).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;  
 
 
 
 
        }  
 
        else if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            //product by activity type  
            GridDropDownListColumnEditor list = (e.Item as GridEditableItem).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;  
 
            RadComboBox ddlActivity = list.ComboBoxControl;  
            ddlActivity.AutoPostBack = true;  
            ddlActivity.SelectedIndexChanged += list_SelectedIndexChanged;  
 
            //activity date by datespan  
            GridDropDownListColumnEditor list2 = (e.Item as GridEditableItem).EditManager.GetColumnEditor("DateID"as GridDropDownListColumnEditor;  
 
            RadComboBox ddlDate = list2.ComboBoxControl;  
 
            if (ddDateSpan.SelectedIndex == 1)  
            {  
 
 
                string[] ddArray = ddDateSpan.SelectedItem.Text.Split('-');  
                DateTime ddStartDate = Convert.ToDateTime(ddArray[0].ToString());  
                DateTime ddEndDate = Convert.ToDateTime(ddArray[1].ToString());  
                int ddStartDay = ddStartDate.Day;  
                int ddEndDay = ddEndDate.Day;  
 
                for (int i = ddStartDay; i <= ddEndDay; i++)  
                {  
                    ddlDate.Items.Add(new RadComboBoxItem(ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString(), ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString()));  
 
                }  
            }  
            else if (ddDateSpan.SelectedIndex == 0)  
            {  
                string[] ddArray = ddDateSpan.SelectedItem.Text.Split('-');  
                DateTime ddStartDate = Convert.ToDateTime(ddArray[0].ToString());  
                DateTime ddEndDate = Convert.ToDateTime(ddArray[1].ToString());  
                int ddStartDay = ddStartDate.Day;  
                int ddEndDay = ddEndDate.Day;  
 
                for (int i = ddStartDay; i <= ddEndDay; i++)  
                {  
                    ddlDate.Items.Add(new RadComboBoxItem(ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString(), ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString()));  
 
                }  
 
            }  
 
        }  
 
    }  
 
 
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem && !e.Item.IsInEditMode)  
        {  
 
            GridDropDownListColumnEditor dateColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("DateID"as GridDropDownListColumnEditor;  
 
            RadComboBox activitiess = dateColumnEditor.ComboBoxControl;  
 
 
            if (DataBinder.Eval(e.Item.DataItem, "activitydate").ToString() != string.Empty)  
            {  
                string sss = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "activitydate")).ToShortDateString();  
 
                string activity = string.Empty;  
                if (sss != string.Empty)  
                {  
                      
                }  
 
            }  
 
 
            GridDropDownListColumnEditor activityColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;  
 
            RadComboBox activities = activityColumnEditor.ComboBoxControl;  
 
            string ss = DataBinder.Eval(e.Item.DataItem, "activity_id").ToString();  
 
            int? activityId = null;  
            if (ss != string.Empty)  
            {  
                activityId = (int)DataBinder.Eval(e.Item.DataItem, "activity_id");  
                 
            }  
 
            if (activityId != null)  
            {  
                GridDropDownListColumnEditor productColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("productgroup"as GridDropDownListColumnEditor;  
 
                RadComboBox productsCombo = productColumnEditor.ComboBoxControl;  
                productColumnEditor.DataSource = GetProductByActivity();//GetProductsByCategory(categoryId.GetValueOrDefault());  
                 
            }  
 
        }  
        else if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            //activity type  
            GridDropDownListColumnEditor activityColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;  
 
            RadComboBox activities = activityColumnEditor.ComboBoxControl;  
            
            string ss = DataBinder.Eval(e.Item.DataItem, "activity_id").ToString();  
 
            int? activityId = null;  
            if (activities.Items.Count > 0 && ss != string.Empty)  
            {  
                activityId = (int)DataBinder.Eval(e.Item.DataItem, "activity_id");  
                 
            }  
 
            if (activityId != null)  
            {  
                GridDropDownListColumnEditor productColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("productgroup"as GridDropDownListColumnEditor;  
 
                RadComboBox productsCombo = productColumnEditor.ComboBoxControl;  
                productColumnEditor.DataSource = GetProductByActivity();//GetProductsByCategory(categoryId.GetValueOrDefault());  
                productColumnEditor.DataBind();  
 
 
                if (productsCombo.Items.Count > 0)  
                {  
 
                    productsCombo.FindItemByValue(DataBinder.Eval(e.Item.DataItem, "product_id").ToString()).Selected = true;  
                }  
            }  
 
 
            GridDropDownListColumnEditor dateColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("DateID"as GridDropDownListColumnEditor;  
 
            RadComboBox activitiess = dateColumnEditor.ComboBoxControl;  
 
            activitiess.Items.Clear();  
            activitiess.Items.Add(new RadComboBoxItem("Choose one"""));  
 
 
            if (ddDateSpan.SelectedIndex == 0)  
            {  
                string[] ddArray = ddDateSpan.SelectedItem.Text.Split('-');  
                DateTime ddStartDate = Convert.ToDateTime(ddArray[0].ToString());  
                DateTime ddEndDate = Convert.ToDateTime(ddArray[1].ToString());  
                int ddStartDay = ddStartDate.Day;  
                int ddEndDay = ddEndDate.Day;  
 
                for (int i = ddStartDay; i <= ddEndDay; i++)  
                {  
                    activitiess.Items.Add(new RadComboBoxItem(ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString(), ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString()));  
 
                }  
            }  
            else 
            {  
                string[] ddArray = ddDateSpan.SelectedItem.Text.Split('-');  
                DateTime ddStartDate = Convert.ToDateTime(ddArray[0].ToString());  
                DateTime ddEndDate = Convert.ToDateTime(ddArray[1].ToString());  
                int ddStartDay = ddStartDate.Day;  
                int ddEndDay = ddEndDate.Day;  
 
                for (int i = ddStartDay; i <= ddEndDay; i++)  
                {  
                    activitiess.Items.Add(new RadComboBoxItem(ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString(), ddStartDate.Month.ToString() + "/" + i + "/" + ddStartDate.Year.ToString()));  
 
                }  
 
            }  
 
 
            if (DataBinder.Eval(e.Item.DataItem, "activitydate").ToString() != string.Empty)  
            {  
                string sss = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "activitydate")).ToShortDateString();  
 
                string activity = string.Empty;  
                if (activities.Items.Count > 0 && sss != string.Empty)  
                {  
 
                    activitiess.SelectedIndex = activitiess.Items.IndexOf(activitiess.Items.FindItemByValue(sss));  
                }  
            }  
 
 
 
 
        }  
    }  
 
 
    
   
    
 
    //onItemCreated  
    private void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        GridEditableItem item = ((Control)sender).NamingContainer as GridEditableItem;  
 
        RadComboBox ddlProduct = item["productgroup"].Controls[0] as RadComboBox;  
        ddlProduct.Items.Clear();  
 
        if (e.Text == "Product")  
        {  
 
            ddlProduct.Items.Add(new RadComboBoxItem("Select One""-1"));  
            foreach (DataRow dr in GetProductByActivity().Rows)  
            {  
                ddlProduct.Items.Add(new RadComboBoxItem(dr["product"].ToString(), dr["obj_id"].ToString()));  
 
 
            }  
 
        }  
 
    }  
 
    //OnItemCreated  
    // product datasource  
    private DataTable GetProductByActivity()  
    {  
 
        SqlConnection newSqlConnection = new SqlConnection(Constring);  
        SqlDataAdapter SQLda = new SqlDataAdapter();  
 
 
 
        using (SQLda.SelectCommand = new SqlCommand("SELECT obj_id as obj_id,[description] as [product] FROM project", newSqlConnection))  
        {  
            DataTable myDataTable = new DataTable();  
            newSqlConnection.Open();  
 
            try 
            {  
                SQLda.Fill(myDataTable);  
                return myDataTable;  
 
            }  
 
            finally 
            {  
                newSqlConnection.Close();  
 
            }  
 
        }  
 
 
    }  
 
    //onItemDataBound  
    protected DataTable GetActivity()  
    {  
        return ((DataView)SqlDataSource_ActivityType.Select(new DataSourceSelectArguments())).Table;  
    }  
 
 
     
    public void GetStatus_Next(object sender, System.EventArgs e)  
    {  
        RadGrid1.Visible = false;  
        RadGrid2.Visible = true;  
        btnNext.Visible = false;  
        btnBack.Visible = true;  
 
        RadGrid2.MasterTableView.EditMode = GridEditMode.InPlace;  
        int i = 0;  
        foreach (GridDataItem GridItem in RadGrid1.Items)  
        {  
 
            using (SqlCommand SQLCommand = new SqlCommand("[system/engines/myactivity/default/updategriditems]"new SqlConnection(Constring)))  
            {  
                SQLCommand.CommandType = CommandType.StoredProcedure;  
 
 
 
 
                SQLCommand.Parameters.Add("@key", SqlDbType.Int, 4).Value = RadGrid1.Items[0].OwnerTableView.DataKeyValues[GridItem.ItemIndex]["key"];  
                SQLCommand.Parameters.AddWithValue("@sid", escWorks.Configuration.CurrentUser.Identity);  
                SQLCommand.Parameters.AddWithValue("@user_id", escWorks.Configuration.CurrentUser.UserId);  
                SQLCommand.Parameters.AddWithValue("@datespan_id", ddDateSpan.SelectedItem.Value);  
 
                SQLCommand.Connection.Open();  
 
                try 
                {  
                    SQLCommand.ExecuteNonQuery();  
                    i++;  
                }  
 
                catch (Exception ex)  
                {  
                    Response.Write(ex.Message);  
 
                }  
 
                finally 
                {  
                    if (SQLCommand.Connection.State != ConnectionState.Closed)  
                        SQLCommand.Connection.Close();  
 
                }  
 
 
            }  
 
        }  
 
 
    }  
 
    public void GetStatus_Previous(object sender, System.EventArgs e)  
    {  
        RadGrid1.Visible = true;  
        RadGrid2.Visible = false;  
        btnNext.Visible = true;  
        btnBack.Visible = false;  
 
 
 
 
 
    }  
     
 
    private void PopulateDateSpan()  
    {  
        ddDateSpan.DataSource = GetActivityDateSpan();  
        ddDateSpan.DataTextField = "display";  
        ddDateSpan.DataValueField = "key";  
        ddDateSpan.DataBind();  
 
        ddDateSpan.SelectedIndex = ddDateSpan.Items.IndexOf(ddDateSpan.Items.FindByValue(Request.Form["ddDateSpan"]));  
 
 
 
    }  
 
    private DataSet GetActivityDateSpan()  
    {  
        using (SqlCommand SQLCommand = new SqlCommand("system/engines/myactivity/default/datespan"new SqlConnection(Constring)))  
        {  
            SQLCommand.CommandType = CommandType.StoredProcedure;  
            SQLCommand.Connection.Open();  
 
            try 
            {  
                DataSet SQLds = new DataSet("result");  
 
                SqlDataAdapter SQLda = new SqlDataAdapter(SQLCommand);  
 
                SQLda.Fill(SQLds);  
 
                return SQLds;  
            }  
 
            catch (Exception ex)  
            {  
                return null;  
                Response.Write(ex.Message);  
            }  
 
            finally 
            {  
                if (SQLCommand.Connection.State != ConnectionState.Closed)  
                    SQLCommand.Connection.Close();  
 
            }  
 
 
        }  
 
    }  
 
 
}  
 

7 Answers, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 22 Nov 2008, 10:21 AM
Hi,

Are you trying to display and bind RadComboBox in grid column when the grid is in read mode (not edit mode)?

If yes, you can use GridTemplateColumn with RadComboBox in its ItemTemplate. With GridDropDownColumn, the drop down control is only available in edit/insert mode.

Check out this link for more info.
0
Zash
Top achievements
Rank 1
answered on 23 Nov 2008, 02:27 PM
Basically I have four dropdowncontrol in RadGrid1. datasource for activity type and budget defined in design time but for product and activity date datasource is defined in server side. when i insert a new item product and activity date does not show up in the grid.
I thought i need to have coding in RadGrid1_ItemDataBound and RadGrid1_ItemCreated for that. Is my understanding right?. Could you give me any sample example. On insert mode and Edit mode actividate and product binds to grid control but once you updated or inserted , the activitydate and product does not show up/bind to RadGrid1.

67     protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)     
68     {     
69     
70         if (e.Item is GridDataItem && e.Item.IsInEditMode)     
71         {     
72             GridDropDownListColumnEditor list = (e.Item as GridEditableItem).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;     
73     
74     
75     
76     
77         }     
 



protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)     
132     {     
133         if (e.Item is GridDataItem && !e.Item.IsInEditMode)     
134         {     
135     
136             GridDropDownListColumnEditor dateColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("DateID"as GridDropDownListColumnEditor;     
137     
138             RadComboBox activitiess = dateColumnEditor.ComboBoxControl;     
139     
140     
141             if (DataBinder.Eval(e.Item.DataItem, "activitydate").ToString() != string.Empty)     
142             {     
143                 string sss = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "activitydate")).ToShortDateString();     
144     
145                 string activity = string.Empty;     
146                 if (sss != string.Empty)     
147                 {     
148                          
149                 }     
150     
151             }     
152     
153     
154             GridDropDownListColumnEditor activityColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("ActivityTypeID"as GridDropDownListColumnEditor;     
155     
156             RadComboBox activities = activityColumnEditor.ComboBoxControl;     
157     
158             string ss = DataBinder.Eval(e.Item.DataItem, "activity_id").ToString();     
159     
160             int? activityId = null;     
161             if (ss != string.Empty)     
162             {     
163                 activityId = (int)DataBinder.Eval(e.Item.DataItem, "activity_id");     
164                     
165             }     
166     
167             if (activityId != null)     
168             {     
169                 GridDropDownListColumnEditor productColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("productgroup"as GridDropDownListColumnEditor;     
170     
171                 RadComboBox productsCombo = productColumnEditor.ComboBoxControl;     
172                 productColumnEditor.DataSource = GetProductByActivity();//GetProductsByCategory(categoryId.GetValueOrDefault());     
173                     
174             }     
175     
176         }    
 
0
Iana Tsolova
Telerik team
answered on 24 Nov 2008, 12:43 PM
Hello Ami,

Can you confirm that your database is updated properly after insert/update?
Additionally, I suggest that you review this help topic on how to configure/customize GridDropDownColumn and verify you have set up you columns right.

Let me know how it goes.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Zash
Top achievements
Rank 1
answered on 24 Nov 2008, 01:53 PM
Hi Lana,

yes, the value of activitydate and product_id is being written in database table during insert and update mode.In database datatype for activitydate is set as Nvarchar(500) and product_id as int. The problem i'm having here is activity date and product does not bind to grid control right after insert or update a grid item.

So you are saying i don't need any code in the RadGrid1_ItemCreated  event handler for the condition of 

 

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem && e.Item.IsInEditMode)

 

{

 

GridDropDownListColumnEditor list = (e.Item as GridEditableItem).EditManager.GetColumnEditor("ActivityTypeID") as GridDropDownListColumnEditor;

 

 

 

}

and
RadGrid1_ItemDataBound eventhandler for the condition of

 

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridDataItem && !e.Item.IsInEditMode)

 

{

 

GridDropDownListColumnEditor dateColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("DateID") as GridDropDownListColumnEditor;

 

 

RadComboBox activitiess = dateColumnEditor.ComboBoxControl;

 

 

}

Please let me know.Thanks

0
Iana Tsolova
Telerik team
answered on 24 Nov 2008, 02:18 PM
Hello Ami,

You might handle the ItemCreated and/or ItemDataBound events in case you need to perform additional configurations and customizations there. Otherwise you are not obliged to.

Can you verify that you have set the ListTextField, ListValueField, DataField and DataSourceID/DataMember properties of the problematic GridDropDownColumns as explained here?

All the best,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Zash
Top achievements
Rank 1
answered on 24 Nov 2008, 04:55 PM

You are right i did not have those property set in design time as datasource for activitydate griddropdowncolumn i have defined in code behind.I have DataField only set in design time and other property i have defined in code behind.

This is what i'm doing in the Grid1_ItemDataBound Eventhandler

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

 

 

 

if (e.Item is GridDataItem && !e.Item.IsInEditMode)

 

{

 

 

 

 

GridDropDownListColumnEditor dateColumnEditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("DateID") as GridDropDownListColumnEditor;

 

 

 

 

 

DropDownList ddActivity = dateColumnEditor.DropDownListControl;

 

 

 

 

 

foreach (GridDataItem GridItem in RadGrid1.Items)

 

{

ddActivity.DataSource = BindActivityDate(GridItem.OwnerTableView.DataKeyValues[GridItem.ItemIndex][

 

 

 

"key"]);

 

ddActivity.DataTextField =

 

 

 

"activitydate";

 

ddActivity.DataValueField =

 

 

 

"activitydate";

 

ddActivity.DataBind();

 

}

But still not showing.Thanks

 

 

 

0
Iana Tsolova
Telerik team
answered on 26 Nov 2008, 01:36 PM
Hi Ami,

Please try setting the ListTextField and ListValueField properties of the GridDropDownColumn in the apsx file, directly in the column declaration. Then you can use the following code in order to change the GridDropDownColumn datas source:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridDataItem)  
    {  
        GridDataItem item = e.Item as GridDataItem;  
        GridDropDownListColumnEditor editor = item.EditManager.GetColumnEditor("DateID"as GridDropDownListColumnEditor;  
        editor.DataSource = BindActivityDate(GridItem.OwnerTableView.DataKeyValues[GridItem.ItemIndex]["key"]);  
    }  

I hope this helps.

Greetings,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Zash
Top achievements
Rank 1
Answers by
SamJ
Top achievements
Rank 1
Zash
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or