Click here to Skip to main content
15,886,919 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: identifying the isp of the user Pin
Manas Bhardwaj4-Jun-09 5:07
professionalManas Bhardwaj4-Jun-09 5:07 
AnswerRe: identifying the isp of the user Pin
Christian Graus4-Jun-09 16:29
protectorChristian Graus4-Jun-09 16:29 
Question.Net Membership provider Pin
anandhakrishnan4-Jun-09 3:03
anandhakrishnan4-Jun-09 3:03 
Questionrepeater control in ASP.Net with C# Pin
mahichandu4-Jun-09 3:02
mahichandu4-Jun-09 3:02 
AnswerRe: repeater control in ASP.Net with C# Pin
Manas Bhardwaj4-Jun-09 3:30
professionalManas Bhardwaj4-Jun-09 3:30 
QuestionRe: repeater control in ASP.Net with C# Pin
mahichandu4-Jun-09 3:45
mahichandu4-Jun-09 3:45 
AnswerRe: repeater control in ASP.Net with C# Pin
Niladri_Biswas1-Jul-09 5:57
Niladri_Biswas1-Jul-09 5:57 
AnswerRe: repeater control in ASP.Net with C# Pin
Niladri_Biswas4-Jun-09 19:25
Niladri_Biswas4-Jun-09 19:25 
There are may ways of doing the same.
I am presenting one way of doing it

I am taking a datatable as my datasource(and ofcourse you have also taken that Smile | :) )

So here it goes

Step 1: Create datatable

DataTable dtSource = new DataTable();

        #region Data Table Creation

        dtSource.Columns.Add("Jurdiction");
        dtSource.Columns.Add("2007");
        dtSource.Columns.Add("2008");
        dtSource.Columns.Add("2009");        

        #endregion

        #region Add Rows
        dtSource.Rows.Add("NC", "0", "6", "3");
        dtSource.Rows.Add("VA", "4", "0", "5");
        dtSource.Rows.Add("NY", "0", "7", "0");
        
        #endregion


Step 2:Create a repeater control in your .aspx page

<asp:Repeater ID="myRepeater" runat="server">
    </asp:Repeater>


Step 3:Bind the datatable to the repeater control which is there in the .aspx page

myRepeater.DataSource = dtSource;
        myRepeater.DataBind();


Step 4:Create a user control say Headercontrol.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HeaderControl.ascx.cs" Inherits="HeaderControl" %>
<table width="40%">
    <tr>
        <td style="width:10%">
            <asp:Label ID="lblHeaderCol1" runat="server" Text="Jurdiction"></asp:Label>
        </td>
        <td style="width:10%">
            <asp:Label ID="lblHeaderCol2" runat="server" Text="2007"></asp:Label>
        </td>
        <td style="width:10%">
            <asp:Label ID="lblHeaderCol3" runat="server" Text="2008"></asp:Label>
        </td>        
        <td style="width:10%">
            <asp:Label ID="lblHeaderCol4" runat="server" Text="2009"></asp:Label>
        </td>
    </tr>
    </table>


Step 5:Create another user control say ContentControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContentControl.ascx.cs" Inherits="ContentControl" %>

<table width="40%">
    <tr>
        <td style="width:10%">
            <asp:Label ID="lblContentColumn1" runat="server"></asp:Label>
        </td>
        <td style="width:10%">
           <asp:LinkButton ID="lnkContentColumn2" runat="server"></asp:LinkButton>
        </td>
        <td style="width:10%">
            <asp:LinkButton ID="lnkContentColumn3" runat="server"></asp:LinkButton>
        </td>
        <td style="width:10%">
            <asp:LinkButton ID="lnkContentColumn4" runat="server"></asp:LinkButton>
        </td>
    </tr>
</table>


Step 6:Expose the following properties in the ContentControl.ascx.cs

#region Properties

    public string Jurdiction { get; set; }

    public string Content2007 { get; set; }

    public string Content2008 { get; set; }

    public string Content2009 { get; set; }

    #endregion


Step 7: In the Page_Load event of ContentControl.ascx.cs, add the following

protected void Page_Load(object sender, EventArgs e)
    {
        lblContentColumn1.Text = Jurdiction;

        lnkContentColumn2.Text = Content2007;

        lnkContentColumn3.Text = Content2008;

        lnkContentColumn4.Text = Content2009;       
    }


Step 8: Call the Header.ascx user control from inside the <HeaderTemplate> of the repeater and the ContentControl.ascx from inside the <ItemTemplate> of the repeater.


It is given below

<asp:Repeater ID="myRepeater" runat="server">
        <HeaderTemplate>
       <uc2:HeaderControl ID="HeaderControl1" runat="server" />
        </HeaderTemplate>
        <ItemTemplate>
            <uc1:WebUserControl ID="WebUserControl1" runat="server" Jurdiction=<%# DataBinder.Eval(Container.DataItem, "Jurdiction")%> Content2007=<%# DataBinder.Eval(Container.DataItem, "2007")%> Content2008=<%# DataBinder.Eval(Container.DataItem, "2008")%> Content2009=<%# DataBinder.Eval(Container.DataItem, "2009")%> Counter = <%# Container.ItemIndex%> />
         </ItemTemplate> 
        </asp:Repeater>



N.B.~ The various properties that I have exposed from the ContentControl.ascx, are consumed inside the itemtemplate.



So What I am doing?

Basically in the header user control , I have defined the Column names to be printed

and in the ContentUserControl I have attached the cell values to the link buttons.

I am calling the user control from inside the item template ; so each time the user control will be iterated.

N.B.~ This is one of the solutions that came in my mind instantly.


Hope it will help you.
Smile | :)

Niladri Biswas

QuestionListBox DataValueField Pin
Koss_G4-Jun-09 1:51
Koss_G4-Jun-09 1:51 
Questionhow to handle in code to remove security dialoag in IE 6 in C#? Pin
anish27patel4-Jun-09 1:42
anish27patel4-Jun-09 1:42 
AnswerRe: how to handle in code to remove security dialoag in IE 6 in C#? Pin
Manas Bhardwaj4-Jun-09 3:32
professionalManas Bhardwaj4-Jun-09 3:32 
Questionoutlook to database...? Pin
koolprasad20034-Jun-09 0:59
professionalkoolprasad20034-Jun-09 0:59 
AnswerRe: outlook to database...? Pin
Abhijit Jana4-Jun-09 1:18
professionalAbhijit Jana4-Jun-09 1:18 
QuestionRM Files Pin
hadad4-Jun-09 0:39
hadad4-Jun-09 0:39 
Questionhow to open msn messenger..... Pin
bhuraasif4-Jun-09 0:36
bhuraasif4-Jun-09 0:36 
AnswerRe: how to open msn messenger..... Pin
Christian Graus4-Jun-09 11:48
protectorChristian Graus4-Jun-09 11:48 
AnswerRe: how to open msn messenger..... Pin
RichardGrimmer5-Jun-09 0:53
RichardGrimmer5-Jun-09 0:53 
Questionset binary image in Image web control. Pin
andiyuniar4-Jun-09 0:26
andiyuniar4-Jun-09 0:26 
AnswerRe: set binary image in Image web control. Pin
Ryomin4-Jun-09 5:55
professionalRyomin4-Jun-09 5:55 
GeneralRe: set binary image in Image web control. Pin
andiyuniar4-Jun-09 16:18
andiyuniar4-Jun-09 16:18 
QuestionJQuery AJax Problem Pin
Jagz W3-Jun-09 23:38
professionalJagz W3-Jun-09 23:38 
AnswerRe: JQuery AJax Problem Pin
Christian Graus3-Jun-09 23:53
protectorChristian Graus3-Jun-09 23:53 
Questionusing timer to refresh gridview Pin
Arif Liminto3-Jun-09 22:53
professionalArif Liminto3-Jun-09 22:53 
AnswerRe: using timer to refresh gridview Pin
K03063-Jun-09 23:05
K03063-Jun-09 23:05 
GeneralRe: using timer to refresh gridview Pin
Christian Graus3-Jun-09 23:27
protectorChristian Graus3-Jun-09 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.