今天学习了GridView控件的使用方法,下面我来做一下总结
GridView的使用要从两方面考虑:
1.设置GridView的外观
2.制定GridView的列
GridView的外观:
整体外观控制:布局、分页、外观
行外观控制:项、交替项、编辑项、选中项、页眉、页脚、分页、空数据项
制定GridView的列:
绑定列
超级链接列
图片列
复选框列
按钮列
命令列
模版列
删除:
if (e.Row.RowType!=DataControlRowType.DataRow)
{
return;
}
LinkButton lbtn=e.Row.Cells[6].Controls[0] as LinkButton;
string sname=e.Row.Cells[1].Text;
if (lbtn!=null)
{
lbtn.Attributes.Add("onclick", "return confirm('确信要删除"+sname+"吗?')");
}
前台绑定字段
<td class="style10">
班级编号:</td>
<td>
<%#Eval("classid") %></td>
前台:点击姓名在另一页面显示图片
<td>
姓名:<a href='ViewPhoto.aspx?photourl=<%# Eval("photo") %>' target="_blank"><%# Eval("sname") %></a></td>
</tr>
鼠标悬停在图片上时显示说明文字:
<asp:Image ID="Image1" ToolTip='<%# "这是:" + Eval("sname") %>' Width="60px" Height="60px" runat="server" ImageUrl='<%# Eval("photo") %>'