Feeds:
Posts
Comments

Archive for August, 2008

This is a big problem if you do things like Invoice Reports for example and I see it as a basic and very common needed feature. Luckily there is a work around.

WorkAround1: Using Shared Property Code

Add the following Code under Report->Report Properties->Code

Shared strTitle As String
Public Shared Function HeaderTitle(ByVal Value As String)As String
    strTitle=Value
End Function

Add a textbox on the body of the Report, set textbox visisble is false and add the following expression

=Code.HeaderTitle(First(Fields!TicketNumber.Value, “DS1”))

Add the TextBox or Lable on the header and set the expression as

=Code.strTitle

Page header data will repeat on every page with this approch.

But In multi user environment it will create some problems. Since it is using shared variable the same data may be served for the different users.

WorkAround2: Using Report Parameters (Best One with my Knowledge)

Add the ReportParameter called ReportTitle and set the Default Value from the dataset(Better have seperate dataset).
Set this Report Parameter as Hidden.
      
Add the TextBox or Lable on the header and set the expression as

=Parameters!ReportTitle.Value

Page header data will repeat on every page with this approch with out any problem.

Read Full Post »

Declare a dropdown as usual in the master page

<asp:DropDownList ID=”drpLanguage” runat=”server” AutoPostBack=”True”  OnSelectedIndexChanged=”drpLanguage_SelectedIndexChanged” >
    <asp:ListItem  Value=”en-US” Selected=True>English</asp:ListItem>
    <asp:ListItem  Value=”de-DE”>German</asp:ListItem>
</asp:DropDownList>

Add Dropdown ClientId to the Session Variable on Master Page init event

protected void Page_Init(object sender, EventArgs e)
 {
    Session[“DDLUniqueID”] = drpLanguage.UniqueID;
 }

Add selected language value to the session

protected void drpLanguage_SelectedIndexChanged(object sender, EventArgs e)
 {

    Session[“Language”] = drpLanguage.SelectedItem.Value.ToString();
     
 }

To keep Dropdown selected value in the page transfers, Use the following logic to select dropdown value from the session.

protected void Page_Load(object sender, EventArgs e)
 {    
     if (!IsPostBack)
        {
            if (Session[“Language”] != null)
            {
                drpLanguage.ClearSelection();
                drpLanguage.Items.FindByValue(Session[“Language”].ToString()).Selected = true;
            }
            else
            {
                drpLanguage.ClearSelection();
                drpLanguage.Items.FindByValue(“en-US”).Selected = true;
            }
        }
 }

Create a base page. All webpages will inherit from the base page.
Add the the following methods the Base page.

protected override void InitializeCulture()
 {
            string selectedCulture = string.Empty;
            if (Session[“DDLUniqueID”] != null) // first time this will be null
            {
                string id = Session[“DDLUniqueID”].ToString();
                selectedCulture = Request.Form[id]; // this will get the selected value.
                SetCulture(selectedCulture);
            }         
            else
            {
                SetCulture(“en-US”);  //Default English.
            }
   
        base.InitializeCulture();
 }

private void SetCulture(string strLan)
 {             
        System.Globalization.CultureInfo lang = new System.Globalization.CultureInfo(strLan);
        System.Threading.Thread.CurrentThread.CurrentCulture = lang;
        System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
 }

 
 
Notice, there is absolutely no code in any of the content pages. Thats it ten lines of code and we are done for the whole site. This is not complete code, just a tip and trick of using master page and the base page globalize code.

Read Full Post »