实现功能:gridview中添加图片显示
.aspx文件代码
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:ConnectionString%>"
SelectCommand=" select * from FriendsLink order by ID desc" DeleteCommand="delete from FriendsLink where ID=@ID" UpdateCommand="update FriendsLink set LinkName=@LinkName,LinkAdress=@LinkAdress,LinkPicPath=@LinkPicPath where ID=@ID">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ForeColor="#333333"
BorderWidth="1px" RowStyle-HorizontalAlign="Center" CellPadding="3" GridLines="Vertical"
Width="760px" DataKeyNames="ID" PageSize="15">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="./showLink.aspx?ID={0}"
DataTextField="LinkName" HeaderText="详细信息" />
<asp:ImageField DataImageUrlField="LinkPicPath" DataImageUrlFormatString="{0}" HeaderText="Logo">
</asp:ImageField>
<asp:BoundField DataField="LinkName" HeaderText="链接名称" SortExpression="LinkName" />
<asp:BoundField DataField="LinkAdress" HeaderText="链接地址" SortExpression="LinkAdress" />
<asp:CommandField ShowEditButton="true" HeaderText="编辑" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
SelectCommand=" select * from FriendsLink order by ID desc" DeleteCommand="delete from FriendsLink where ID=@ID" UpdateCommand="update FriendsLink set LinkName=@LinkName,LinkAdress=@LinkAdress,LinkPicPath=@LinkPicPath where ID=@ID">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ForeColor="#333333"
BorderWidth="1px" RowStyle-HorizontalAlign="Center" CellPadding="3" GridLines="Vertical"
Width="760px" DataKeyNames="ID" PageSize="15">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="./showLink.aspx?ID={0}"
DataTextField="LinkName" HeaderText="详细信息" />
<asp:ImageField DataImageUrlField="LinkPicPath" DataImageUrlFormatString="{0}" HeaderText="Logo">
</asp:ImageField>
<asp:BoundField DataField="LinkName" HeaderText="链接名称" SortExpression="LinkName" />
<asp:BoundField DataField="LinkAdress" HeaderText="链接地址" SortExpression="LinkAdress" />
<asp:CommandField ShowEditButton="true" HeaderText="编辑" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
aspx.cs文件中啥也不用写
效果如下:
不足之处:编辑时只能修改图片链接地址,而无法重新上传图片文件..可以考虑打开新的页面完成操作..不做赘述了就
外加一个参考链接吧:http://hi.baidu.com/yanghuhu/blog/item/22c471ee9b75851afdfa3c1a.html