现在又一个GridView 显示数据库中的一个表(UserInfor),然后我有一个模板列(删除) 我想实现这样的效果,在我打开UserList 页面的时候,同时找出姓名是admin(管理员)的记录,
然后把与此记录相对应的LinkButten(即删除)在GridView 中不显示出来,请问各位怎么写啊?
然后把与此记录相对应的LinkButten(即删除)在GridView 中不显示出来,请问各位怎么写啊?
解决方案 »
- objectdatasource與業務邏輯類綁定問題
- 新手提问:textbox最大长度问题。。
- asp.net2003连接SQLServer2005 Express的问题,求助!
- htmlfile: 由于该控件目前不可见、未启用或其类型不允许,因此无法将焦点移向它。
- 菜鸟来了!!!
- 丢掉了CS代码,还有个Dll文件,可否有办法还原为CS文件?由于文件比较大,所以想此招。
- char[] chSplit = {'.'}; 这句C#用VB怎么写?
- word文档中插入microsoft visio对象出错 怎么解决
- 百度云文件上传功能如何实现的?
- 急问删除问题
- discuz!NT登录代码解析
- |zyciis| 服务器控件已经有像Repeater的格式了,那如何进行数据绑定呢?,谢谢
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
if (this.GridView1.DataKeys[e.Row.RowIndex][1].ToString() == "管理员")
{
((LinkButton)e.Row.FindControl("lbtnDel")).Visible = false;
}
else
{
((LinkButton)e.Row.FindControl("lbtnDel")).Visible = true;
}
}
}
}
2楼说AJAX,具体说说看,我想不出来怎么做。。
userName!='admin' 就行了
或者就用上面 一行一行判断
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="100%" DataKeyNames="UserId" Height="110px"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="5"
AllowPaging="True" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="工号">
<ItemTemplate>
<asp:Label ID="lblUserId" runat="server" Text='<%# Bind("UserId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="姓名">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="权限">
<ItemTemplate>
<asp:Label ID="lblLimitLevel" runat="server" Text='<%# Bind("LimitLevel") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<asp:LinkButton ID="lkbtnEdit" runat="server" PostBackUrl='<%#"~/User_edit.aspx?UserId="+Eval("UserId").ToString() %>'>编辑</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:LinkButton ID="lkbtnDelete" runat="server" onclientclick="if(!confirm( '确定删除? ')) return false; "
CommandArgument='<%# Eval("UserId").ToString() %>' CommandName="De">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<table style="font-size :12px; margin-left: 0px; height: 15px; margin-bottom: 0px;"
align="right" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="height: 25px">
</td>
<td style="height: 25px;width:10px">
</td>
<td style="height: 20px">
总共
<asp:Label ID="Label1" runat="server"
Text="<%#((GridView)Container.NamingContainer).PageCount %>"> </asp:Label>
页
</td>
<td style="height: 25px">
第
<asp:Label ID="Label2" runat="server"
Text="<%#((GridView)Container.NamingContainer).PageIndex+1 %>"> </asp:Label>
页 </td>
<td style="height: 25px">
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="1"
CommandName="Page"
Enabled="<%#((GridView)Container.NamingContainer).PageIndex!=0 %>">首页</asp:LinkButton>
</td>
<td style="height: 25px">
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="Prev"
CommandName="Page"
Enabled="<%#((GridView)Container.NamingContainer).PageIndex!=0 %>">上一页</asp:LinkButton>
</td>
<td style="height: 25px">
<asp:LinkButton ID="LinkButton3" runat="server" CommandArgument="Next"
CommandName="Page"
Enabled="<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1 %>">下一页
</asp:LinkButton>
</td>
<td style="height: 25px">
<asp:LinkButton ID="LinkButton4" runat="server" CommandArgument="Last"
CommandName="Page"
Enabled="<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1 %>">尾页</asp:LinkButton>
</td>
<td style="height: 25px">
<td style="height: 25px">
<asp:TextBox ID="txtNum" runat="server" Width="30px"
Text="<%#((GridView)Container.NamingContainer).PageIndex+1 %>"
ValidationGroup="1">
</asp:TextBox>
<asp:LinkButton ID="LinkButton5" runat="server" CommandArgument="-1"
CommandName="Page" ValidationGroup="1">GO</asp:LinkButton>
</td>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="" ValidationExpression="^\d+$" ControlToValidate="txtNum"
ValidationGroup="1">
</asp:RegularExpressionValidator>
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
大哥还是不行啊 我DEBUG了一下发现e.Row.Cells[1].Text 总是为“”空啊,上面原因呢?
你这里使用了模板列,就要使用((Lable)e.Row.FindControl("lblName")).Text=="admin"了