怎么获得数据,并显示
<table><tr>
<td>xxx:<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("image") %>'/></td>
</tr>
<tr>
<td>xxx:<asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>' /> </td>
</tr>
<tr><td>xxx:<asp:Label ID="RestName" runat="server" Text='<%# Eval("name") %>' /></td>
</tr>
</table>
SqlConnection conn = new SqlConnection("server=.;database=RestOL;uid=sa;pwd=123456;");
conn.Open();
SqlCommand sql = new SqlCommand("select * from Dishes ", conn); //有3列
SqlDataAdapter sda = new SqlDataAdapter(sql);
DataSet ds = new DataSet();
sda.Fill(ds);
int n = ds.Tables[0].Rows.Count;
for (int i = 0; i < n; i++)
{
this.Image1.ImageUrl = ds.Tables[0].Rows[i][0].ToString();
this.Label1.Text = ds.Tables[0].Rows[i][1].ToString();
this.RestName.Text = ds.Tables[0].Rows[i][2].ToString();
}
conn.Close();
[此贴子已经被作者于2017-4-5 22:40编辑过]