PDA

View Full Version : Problems while getting source of propertygrid



yossi
Jan 24, 2010, 10:47 AM
Hi,
I have problems when i m trying to get the source of the propertygrid.
I get empty collection when i do SponseredLinksGrid.Source although i have some changed rows on the propertygrid.

Attached my code:






<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BrandToolbar.SearchAdmin.SponseredLinks.Default" %>


<%@ Import Namespace="System.Collections.Generic" %>


<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>


<!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>Sponsored Links</title>


</head>


<body>


<form id="form1" runat="server">


<ext:ScriptManager ID="ScriptManager1" runat="server" />





<ext:ViewPort ID="ViewPort1" runat="server" >


<Body>


<ext:BorderLayout ID="BorderLayout1" runat="server">


<Center MarginsSummary="0 5 0 5">


<ext:Panel ID="Panel" runat="server" Height="300" Header="false">


<Body>


<ext:FitLayout ID="FitLayout" runat="server">


<ext:PropertyGrid ID="SponseredLinksGrid" runat="server" Width="150" AutoHeight="true" >





<TopBar>


<ext:Toolbar ID="SelectCTID" runat="server" Height="30">


<Items>


<ext:ToolbarTextItem ID="lblForCbox" runat="server" Text="Type: "></ext:ToolbarTextItem>


<ext:ComboBox ID="TypeCBox" runat="server" AllowBlank="false">


<Items>


<ext:ListItem Text="CT-ID" Value="1" />


<ext:ListItem Text="Toolbar name" Value="2" />


</Items>


<SelectedItem Value="1" />


</ext:ComboBox>


<ext:ToolbarSeparator ID="Seperator" runat="server"></ext:ToolbarSeparator>


<ext:ToolbarTextItem ID="toolbartxt" runat="server" Text="Toolbar: "></ext:ToolbarTextItem>


<ext:TextField ID="SearchText" runat="server" EmptyText="Enter a toolbar to search..." EnableKeyEvents="true" Width="200"></ext:TextField>


<ext:ToolbarButton ID="SearchButton" runat="server" Text="Go!" Icon="Magnifier" >


<AjaxEvents>


<Click OnEvent="SearchMethod" />


</AjaxEvents>


</ext:ToolbarButton>


</Items>


</ext:Toolbar>


</TopBar>





<View>


<ext:GridView ID="GridView1" ForceFit="true" ScrollOffset="2" runat="server" />


</View>


<Listeners>


<Render Handler="this.getStore().sortInfo = undefined;this.getColumnModel().setColumnHeader(0, 'Sponsored Links Type');this.getColumnModel().setColumnHeader(1, 'Ammount');" />


</Listeners>


<Buttons>


<ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">


<ToolTips>


<ext:ToolTip runat="server" ID="saveBtnTooltip" Title="Save the sponsered links values" ></ext:ToolTip>


</ToolTips>


<AjaxEvents>


<Click OnEvent="SaveClick" Before="#{SponseredLinksGrid}.stopEditing(false);" >


<EventMask ShowMask="true" MinDelay="500" Msg="Saving..." />


</Click>


</AjaxEvents>


</ext:Button>


<ext:Button ID="btnRestore" runat="server" Text="Restore" Icon="ArrowRefresh">


<ToolTips>


<ext:ToolTip runat="server" ID="restoreBtnTooltip" Title="Restore the default values." ></ext:ToolTip>


</ToolTips>


<AjaxEvents>


<Click OnEvent="RestoreClick">


</Click>





</AjaxEvents>


</ext:Button>


</Buttons>


</ext:PropertyGrid>


</ext:FitLayout>


</body>


</ext:Panel>


</Center>


</ext:BorderLayout>


</body>


</ext:ViewPort>





</form>


</body>


</html>



My code-behind is:





using System;


using System.Collections.Generic;


using System.Linq;


using System.Web;


using System.Web.UI;


using System.Web.UI.WebControls;


using BrandToolbar.SearchAdmin.BLL.Views;


using Coolite.Ext.Web;


using BrandToolbar.SearchAdmin.BLL.DataAccess;


namespace BrandToolbar.SearchAdmin.SponseredLinks


{


public partial class Default : System.Web.UI.Page


{


const int NUMBER_OF_SPONSERED_LINKS_TYPES = 7;


static string _currentCtid;





protected void Page_Load(object sender, EventArgs e)


{


if (!IsPostBack)


{








}


}


/// <summary>


/// Handle the Clicking of the search button.


/// </summary>


/// <param name="sender"></param>


/// <param name="e"></param>


protected void SearchMethod(object sender, AjaxEventArgs e)


{


string toolbar = SearchText.Text.Trim();


Dictionary<int,int?> sponseredlinksTypesValues = new Dictionary<int,int?>();


if (String.IsNullOrEmpty(toolbar))


{//Toolbar's name or ctid isn't entered.


Ext.Msg.Alert("Message", "Please enter CTID or toolbar's name!").Show();


return;


}


else


{


if (TypeCBox.SelectedItem.Value.Equals("1"))


{//The search is by CTID


if (!SponseredLinksDataSource.IsCTIDExist(toolbar))


{//The CTID isn't exist.


Ext.Msg.Alert("Message", String.Format("The CTID {0} is not exist!", toolbar)).Show();


return;


}


else


{


//Update the current CTID member to the new CTID


_currentCtid = toolbar;


//Get the sponsered links by the given CTID.


sponseredlinksTypesValues = SponseredLinksDataSource.GetSponseredLinks(toolbar );


}


}


else


{//The search is by toolbar's name.


//Get the CTID by the toolbar's name.


string ctid = SponseredLinksDataSource.GetCTIDByToolbarName(tool bar);


//Update the current CTID member to the new CTID


_currentCtid = ctid;


if (String.IsNullOrEmpty(ctid))


{//There is no ctid that corresponding to the given toolbar's name.


Ext.Msg.Alert("Message", String.Format("Toolbar with the name {0} is not exist!", toolbar)).Show


();


return;


}


//Get the sponsered links by the given CTID.


sponseredlinksTypesValues = SponseredLinksDataSource.GetSponseredLinks(ctid);


}


NumberField numberField = new NumberField


{


AllowBlank = true,


ReadOnly = false,


AllowNegative = false,


AllowDecimals = false,


MinValue = 0,


MinText = "This field must be positive",


MaxValue = 20,


MaxText = "More than 20 sponsered links is not allowed",


SelectOnFocus = true


};





if (sponseredlinksTypesValues.ContainsKey(1))


{


PropertyGridParameter topSponseredeparameter = new PropertyGridParameter("Top Sponsored Links", sponseredlinksTypesValues[1].ToString());


topSponseredeparameter.Mode = ParameterMode.Raw;


topSponseredeparameter.Editor.Add(numberField);


SponseredLinksGrid.Source.Add(topSponseredeparamet er);


}


if (sponseredlinksTypesValues.ContainsKey(2))


{


PropertyGridParameter bottomSponseredeparameter = new PropertyGridParameter("Bottom Sponsored Links", sponseredlinksTypesValues[1].ToString());


bottomSponseredeparameter.Mode = ParameterMode.Raw;


bottomSponseredeparameter.Editor.Add(numberField);


SponseredLinksGrid.Source.Add(bottomSponseredepara meter);


}


if (sponseredlinksTypesValues.ContainsKey(3))


{


PropertyGridParameter sideSponseredeparameter = new PropertyGridParameter("Side Sponsored Links", sponseredlinksTypesValues[1].ToString());


sideSponseredeparameter.Mode = ParameterMode.Raw;


sideSponseredeparameter.Editor.Add(numberField);


SponseredLinksGrid.Source.Add(sideSponseredeparame ter);


}


if (sponseredlinksTypesValues.ContainsKey(4))


{


PropertyGridParameter onlySponseredeparameter = new PropertyGridParameter("Only Sponsored Links", sponseredlinksTypesValues[1].ToString());


onlySponseredeparameter.Mode = ParameterMode.Raw;


onlySponseredeparameter.Editor.Add(numberField);


SponseredLinksGrid.Source.Add(onlySponseredeparame ter);


}


if (sponseredlinksTypesValues.ContainsKey(5))


{


PropertyGridParameter communityTopSponseredeparameter = new PropertyGridParameter("Community Top Sponsored Links", sponseredlinksTypesValues[1].ToString());


communityTopSponseredeparameter.Mode = ParameterMode.Raw;


communityTopSponseredeparameter.Editor.Add(numberF ield);


SponseredLinksGrid.Source.Add(communityTopSponsere deparameter);


}


if (sponseredlinksTypesValues.ContainsKey(6))


{


PropertyGridParameter communitySideSponseredeparameter = new PropertyGridParameter("Community Side Sponsored Links", sponseredlinksTypesValues[1].ToString());


communitySideSponseredeparameter.Mode = ParameterMode.Raw;


communitySideSponseredeparameter.Editor.Add(number Field);


SponseredLinksGrid.Source.Add(communitySideSponser edeparameter);


}


if (sponseredlinksTypesValues.ContainsKey(7))


{


PropertyGridParameter homepageSponseredeparameter = new PropertyGridParameter("HomePage Sponsored Links", sponseredlinksTypesValues[1].ToString());


homepageSponseredeparameter.Mode = ParameterMode.Raw;


homepageSponseredeparameter.Editor.Add(numberField );


SponseredLinksGrid.Source.Add(homepageSponseredepa rameter);


}


SponseredLinksGrid.SetSource(SponseredLinksGrid.So urce);


SponseredLinksGrid.DataBind();


}


}





protected void SaveClick(object sender, AjaxEventArgs e)


{


foreach (PropertyGridParameter parameter in SponseredLinksGrid.Source) //THE PROBLEM IS HERE!!!!!!!!!!!!


{


int sponseredLinkType = SponsoredLinkTypesValues.SponseredLinksStringsType s[parameter.Name];


if (String.IsNullOrEmpty(parameter.Value) )


{


if(SponseredLinksDataSource.IsSponseredLinkTypeVal ueExist(_currentCtid,sponseredLinkType))


{


SponseredLinksDataSource.DeleteSponseredLinkTypeVa lue(_currentCtid,sponseredLinkType);


}


}


else


{


int sponseredLinkValue;


if (!Int32.TryParse(parameter.Value, out sponseredLinkValue))


{


Ext.Msg.Alert("Wrong Ammount", String.Format("The ammount of {0} must be a number between 0-20!", sponseredLinkType)).Show();


continue;


}


SponseredLinksDataSource.UpdateSponseredLinkTypeVa lue(_currentCtid,sponseredLinkType,sponseredLinkVa lue);


}


}





}


protected void RestoreClick(object sender, AjaxEventArgs e)


{


}


}


}


Thanks in advance!!!!
Yossi.