VB.NET
Dim ds As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds = ’Assign proper value to dataset
Dim dc As DataColumn
Dim dr As DataRow
Dim rpthdr As New TemplateBuilder
Dim rptitem As New TemplateBuilder
Dim strval As String
For Each dc In ds.Tables(0).Columns
If strval = '' Then
strval = dc.ColumnName & ' '
Else
strval = strval & dc.ColumnName & ' '
End If
Next
rpthdr.AppendLiteralString(strval)
Repeater1.HeaderTemplate = rpthdr
Repeater1.DataSource = ds
Repeater1.DataBind()
End Sub
Function getData(ByVal objContainer As System.Web.UI.WebControls.RepeaterItem) As String
Dim i As Integer
Dim strval As String = '<br>'
For i = 0 To ds.Tables('table').Columns.Count - 1
If strval = '' Then
strval = objContainer.DataItem(i).ToString & ' '
Else
strval &= objContainer.DataItem(i).ToString & ' '
End If
Next
strval = strval & '<br>'
Return strval
End Function
C#
DataSet ds;
private void Page_Load(object sender, System.EventArgs e)
{
ds = something;
DataColumn dc;
DataRow dr;
TemplateBuilder rpthdr = new TemplateBuilder();
TemplateBuilder rptitem = new TemplateBuilder();
string strval;
foreach (int dc in ds.Tables(0).Columns)
{
if (strval == '')
{
strval = dc.ColumnName + ' ';
}
else
{
strval = strval + dc.ColumnName + ' ';
}
}
rpthdr.AppendLiteralString(strval);
Repeater1.HeaderTemplate = rpthdr;
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
string getData(System.Web.UI.WebControls.RepeaterItem objContainer)
{
int i;
string strval = '<br>';
for (int i = 0; i <= ds.Tables('table').Columns.Count - 1; i++)
{
if (strval == '')
{
strval = objContainer.DataItem(i).ToString + ' ';
}
else
{
strval += objContainer.DataItem(i).ToString + ' ';
}
}
strval = strval + '<br>';
return strval;
}
Share with