没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
2页
首现我们拖入一个DataGridView控件到.aspx页面中,然后绑定你需要显示的列,具体代码如下。 代码如下: <asp ID=”gvDepartList” runat=”server” AutoGenerateColumns=”False” Height=”108px” Width=”600px” xss=removed RowDataBound=”gvDepartList_RowDataRound”> <Columns> <asp:TemplateFiel
资源推荐
资源详情
资源评论
ASP.NET中的中的DataGridView绑定数据和选中行删除功能具体绑定数据和选中行删除功能具体
实例实例
首现我们拖入一个DataGridView控件到.aspx页面中,然后绑定你需要显示的列,具体代码如下。
代码如下:
<asp:GridView ID=”gvDepartList” runat=”server” AutoGenerateColumns=”False”
Height=”108px” Width=”600px” OnRowDeleting=”gvDepartList_RowDeleting”
RowDataBound=”gvDepartList_RowDataRound”>
<Columns>
<asp:TemplateField HeaderText=”部门名称” >
<ItemTemplate>
<asp:Label runat=”server” style=”text-align:center” Text='<%# Eval(“DepartName”) %>’ />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText=”机构” DataField=”BranchId” />
<asp:BoundField HeaderText=”负责人” DataField=”PrincipalUser” />
<asp:BoundField HeaderText=”联系电话” DataField=”ConnectTelNo” />
<asp:BoundField HeaderText=”移动电话” DataField=”ConnectMobileTelNo”/>
<asp:BoundField HeaderText=”传真” DataField=”Faxes” />
<asp:TemplateField HeaderText=”修改”>
<ItemTemplate>
<asp:ImageButton ID=”ImageButton1″ ImageUrl=”../images/edit.gif”
CommandArgument='<%#Eval(“DepartId”) %>’ CommandName=”delete” runat=”server” />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”删除”>
<ItemTemplate>
<asp:ImageButton ImageUrl=”../images/delete.gif” CommandArgument='<%#Eval(“DepartId”) %>’
CommandName=”delete” runat=”server” />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
二:在这个.aspx页面后台的Page_load事件中绑定数据。
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvDepartList.DataSource= new DepartInfoManager().GetDepartInfos(-1);
gvDepartList.DataBind();
}
}
如果我们想添加一个DataGridView的光棒效果,就是每一行鼠标悬浮上去变动背景色啦。
代码如下:
/// <summary>
/// 动态注册脚本(在GridView控件呈现之前) 光棒效果
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
//此处判断只有在数据行在进行脚本注册
if (e.Row.RowType == DataControlRowType.DataRow)
{
//光棒效果
e.Row.Attributes.Add(“onmouseover”,”currentcolor=this.style.backgroundColor;this.style.backgroundColor=’#6699ff'”);
e.Row.Attributes.Add(“onmouseout “, “this.style.backgroundColor=currentcolor”);
LinkButton lnkbtnDel = e.Row.FindControl(“lnkbtnDel”) as LinkButton;
lnkbtnDel.Attributes.Add(“onclick”, “return confirm(‘确定删除吗?’)”);
}
资源评论
weixin_38740827
- 粉丝: 7
- 资源: 947
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功