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(); | |
} | |
} | |
} | |
} | |