我用的是Access数据库,不是SQL。。我贴出来了,,你看一下吧,,
<script runat="server" language="c#">
OleDbConnection thisCON;
void Page_Load(Object Sender,System.EventArgs e)
{
this.imgrid.Items.FindControl("delbtn").Attributes.Add("OnClick","return confirm('确定要删除吗?')");
datacon();
imbind();
}
void datacon()
{
thisCON=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath("dbs/webdata.mdb")+"");
thisCON.Open();
}
void imbind()
{
OleDbDataAdapter thisADPT=new OleDbDataAdapter("Select id,impath from im",thisCON);
DataSet hfSet=new DataSet();
thisADPT.Fill(hfSet,"im");
imgrid.DataSource=hfSet;
imgrid.DataBind();
for(int i=0;i<hfSet.Tables["im"].Rows.Count;i++)
{
if(hfSet.Tables["im"].Rows[i]["impath"].ToString()=="")
{
DataGridItem dgit=imgrid.Items[(int)i];
Image t=(Image)dgit.FindControl("theIM");
t.Visible=false;
}
}
thisCON.Close();
}
</script>
</head>
<body>
<form runat="server" method="post">
<asp:DataGrid runat="server" ID="imgrid" AutoGenerateColumns="false" DataKeyField="id">
<columns>
<asp:TemplateColumn HeaderText="图片">
<itemtemplate><asp:Image runat="server" ID="theIM" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"impath")%>' Width="100px" Height="100px"/></itemtemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>
</form>
</body>
</html>
[此贴子已经被作者于2007-5-19 22:37:44编辑过]