Как заполнить два отдельных повторителя с отдельным именем столбца и значением, соответствующим столбцу
Как заполнить репитер двумя отдельными списками
У меня есть следующий репитер:
<div style="width: 100%; overflow: hidden;">
<asp:Repeater ID="rptLabels" runat="server" ClientIDMode="Static">
<HeaderTemplate>
<div class="hidOverflow setFloatL smallPadLeft" style="width: 45%; float: left;">
</HeaderTemplate>
<ItemTemplate>
<div class="hidOverflow smallPad">
<div class="setFloatL halfWidth vertAlignT">
<asp:Label ID="lbl1" ClientIDMode="Static" runat="server" Text="<%# Container.DataItem.ToString() %>"></asp:Label>
</div>
<div class="setFloatL vertAlignT">
<asp:Label ID="lbl2" ClientIDMode="Static" runat="server" Text="<%# Container.DataItem.ToString() %>"></asp:Label>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptLabels2" runat="server" ClientIDMode="Static">
<HeaderTemplate>
<div class="hidOverflow setFloatL smallPadLeft" style="width: 45%; float: left;">
</HeaderTemplate>
<ItemTemplate>
<div class="hidOverflow smallPad">
<div class="setFloatL halfWidth vertAlignT">
<asp:Label ID="lbl3" ClientIDMode="Static" runat="server" Text="<%# Container.DataItem.ToString() %>"></asp:Label>
</div>
<div class="setFloatL vertAlignT">
<asp:Label ID="lbl4" ClientIDMode="Static" runat="server" Text="<%# Container.DataItem.ToString() %>"></asp:Label>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</div>
Я пытаюсь заполнить имя столбца в каждомlbl1
и значение строки соответствующего столбца в каждомlbl2
, У меня есть следующий код:
List<string> colO = new List<string>();
List<string> colOV = new List<string>();
List<string> colT = new List<string>();
List<string> colTV = new List<string>();
using (SqlConnection conn = new SqlConnection(gloString))
{
string strQuery = @""; //query which generates the dataset
try
{
SqlDataAdapter da = new SqlDataAdapter(strQuery, conn);
DataSet myDataSet = new DataSet();
da.Fill(myDataSet);
DataTable myDataTable = new DataTable();
myDataTable = myDataSet.Tables[0];
for (i = 0; i < myDataSet.Tables[0].Columns.Count / 2; i++)
{
lop += myDataSet.Tables[0].Columns[i].ColumnName + " ";
colO.Add(myDataSet.Tables[0].Columns[i].ColumnName.ToString()); //column name
colOV.Add(myDataSet.Tables[0].Rows[0][i].ToString()); //row value of the column
}
lop += "\n\n";
for (int j = i; j < myDataSet.Tables[0].Columns.Count; j++)
{
lop += myDataSet.Tables[0].Columns[j].ColumnName + " ";
colT.Add(myDataSet.Tables[0].Columns[j].ColumnName.ToString()); //column name
colTV.Add(myDataSet.Tables[0].Rows[0][j].ToString()); //row value of the column
}
rptLabels.DataSource = colO; //I would like to popupate "colO" into "lbl1" and "colOV" into "lbl2" inside "rptLabels" repeater
rptLabels.DataBind();
rptLabels2.DataSource = colT; //I would like to popupate "colT" into "lbl3" and "colTV" into "lbl4" inside "rptLabels2" repeater
rptLabels2.DataBind();
}
catch (SqlException)
{
}
}
Прямо сейчас я могу использовать только один список для источника данных для каждого повторителя. Как я могу изменить код для достижения следующего:
rptLabels.DataSource = colO; //I would like to popupate "colO" into "lbl1" and "colOV" into "lbl2" inside "rptLabels" repeater
rptLabels.DataBind();
rptLabels2.DataSource = colT; //I would like to popupate "colT" into "lbl3" and "colTV" into "lbl4" inside "rptLabels2" repeater
rptLabels2.DataBind();