我有个面板。在我的数据库中,我有一个人员列表..对于运行时的每个人,我在他们下面添加了不同的属性。我希望所有的人被列为一个名单(为每个人单独的名单)。我稍后会添加一些值。
下面是我的.aspx代码
<asp:Panel ID="DR_list" runat="server" Direction="LeftToRight" Height="227px"
HorizontalAlign="Center" ScrollBars="Horizontal" Wrap="False">
<asp:ListView >
</asp:ListView>
</asp:Panel>我的c#代码是
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select drname from --- ",
myConnection);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
//Response.Write(myReader["DrName"].ToString());
int tRows;
int tCells;
List<string> DrNames = new List<string>();
for (tCells = 0; tCells < 4; tCells++)
{
string a = myReader["DrName"].ToString();
Response.Write(a);
DrNames.Add(a);
}
DR_list.Controls.Add(DrNames);
}
}请帮帮我..提前感谢
发布于 2013-03-19 22:09:09
我建议您在面板中添加runat="server“,以便添加此数据,但将数据添加到循环结构的末尾
发布于 2013-03-19 22:19:01
你有没有试过别人建议你这样做?
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select drname from --- ",
myConnection);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
//Response.Write(myReader["DrName"].ToString());
int tRows;
int tCells;
List<string> DrNames = new List<string>();
for (tCells = 0; tCells < 4; tCells++)
{
string a = myReader["DrName"].ToString();
Response.Write(a);
DrNames.Add(a);
}
//adding list box to the panel
yourPanel.Controls.Add(new ListBox(){/*set id to the list here*/});
DR_list.Controls.Add(DrNames);
}
}https://stackoverflow.com/questions/15501398
复制相似问题