C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Programmable Tab Strip using C#


Posted Date: 03 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: Lakshmi MurthyMember Level: Bronze    
Rating: 1 out of 5Points: 10




<%@ Control Language="C#" ClassName="TabStrip" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">

// Tabs to display
public ArrayList Tabs = new ArrayList();

// Current Tab
public int CurrentTabIndex
{
get {return (int) ViewState["CurrentTabIndex"];}
}

// Background color
public Color BackColor
{
get {return (Color) ViewState["BackColor"];}
set {ViewState["BackColor"] = value;}
}

// Selected background color
public Color SelectedBackColor
{
get {return (Color) ViewState["SelectedBackColor"];}
set {ViewState["SelectedBackColor"] = value;}
}

// Foreground color
public Color ForeColor
{
get {return (Color) ViewState["ForeColor"];}
set {ViewState["ForeColor"] = value;}
}

// Selected foreground color
public Color SelectedForeColor
{
get {return (Color) ViewState["SelectedForeColor"];}
set {ViewState["SelectedForeColor"] = value;}
}

// Select method
public void Select(int index) {
// Ensure the index is a valid value
if (index <0 || index >=Tabs.Count)
index = 0;

// Updates the current index. Must write to the view state
// because the CurrentTabIndex property is read-only
ViewState["CurrentTabIndex"] = index;

// Refresh the UI
BindData();

// Fire the event to the client
SelectionChangedEventArgs ev = new SelectionChangedEventArgs();
ev.Position = CurrentTabIndex;
OnSelectionChanged(ev);
}

// Custom event class
public class SelectionChangedEventArgs : EventArgs
{
public int Position;
}

public delegate void SelectionChangedEventHandler(object sender, SelectionChangedEventArgs e);
public event SelectionChangedEventHandler SelectionChanged;

// Helper function that fires the event by executing user-defined code
protected virtual void OnSelectionChanged(SelectionChangedEventArgs e)
{
// SelectionChanged is the event property
if (SelectionChanged != null)
SelectionChanged(this, e);
}


//////////////////////////////////////////////////////////////////////

private void Page_Init(object sender, EventArgs e)
{
if (ViewState["SelectedBackColor"] == null)
SelectedBackColor = Color.White;
if (ViewState["SelectedForeColor"] == null)
SelectedForeColor = Color.Blue;
if (ViewState["BackColor"] == null)
BackColor = Color.Gray;
if (ViewState["ForeColor"] == null)
ForeColor = Color.White;
if (ViewState["CurrentTabIndex"] == null)
ViewState["CurrentTabIndex"] = 0;
}

private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}

private void BindData()
{
__theTabStrip.DataSource = Tabs;
__theTabStrip.DataBind();
}

private Color SetBackColor(object elem)
{
RepeaterItem item = (RepeaterItem) elem;
if (item.ItemIndex == CurrentTabIndex)
return SelectedBackColor;
return BackColor;
}

private Color SetForeColor(object elem)
{
RepeaterItem item = (RepeaterItem) elem;
if (item.ItemIndex == CurrentTabIndex)
return SelectedForeColor;
return ForeColor;
}

private Color SetBorderColor(object elem)
{
RepeaterItem item = (RepeaterItem) elem;
if (item.ItemIndex == CurrentTabIndex)
return SelectedBackColor;
return Color.Black;
}

private void ItemCommand(object sender, RepeaterCommandEventArgs e)
{
Select(e.Item.ItemIndex);
}
</script>

<asp:Repeater runat="server" id="__theTabStrip" OnItemCommand="ItemCommand">
<headertemplate>
<table cellpadding="0" cellspacing="0" border="0" ><tr>
</headertemplate>

<itemtemplate>
<td>
<asp:button runat="server" id="__theTab"
BorderWidth="1px"
BorderStyle="solid"
BorderColor='<%# SetBorderColor(Container) %>'
text='<%# Container.DataItem %>'
font-bold='<%# (Container.ItemIndex == CurrentTabIndex) %>'
backcolor='<%# SetBackColor(Container) %>'
forecolor='<%# SetForeColor(Container) %>' />
</td>
</itemtemplate>

<footertemplate>
</tr></table>
</footertemplate>
</asp:Repeater>




Responses

Author: Ashwathy Rajagopal    08 Mar 2005Member Level: Bronze   Points : 0
Dear Laks,

We were searching for the right code for tabstrip,great u came up with this.
Thanks for the timely help



Author: Ashwathy Rajagopal    08 Mar 2005Member Level: Bronze   Points : 0
Dear Laks,

We were searching for the right code for tabstrip,great u came up with this.
Thanks for the timely help



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: XML Comments and other types of comments
Previous Resource: Arrays in VB.NET
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use