onrowcommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="FirstProjectName" HeaderText="一级项目" />
<asp:BoundField DataField="SecondProjectName" HeaderText="二级项目" />
<asp:BoundField DataField="ThridProjectName" HeaderText="三级项目" />
<asp:BoundField DataField="recoupecontent" HeaderText="报销内容" />
<asp:BoundField DataField="recoupemoney" HeaderText="预报销金额(元)" />
<asp:BoundField DataField="recoupetime" HeaderText="报销时间" />
<asp:BoundField DataField="handingperson" HeaderText="经手人" />
<asp:TemplateField HeaderText="状态">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="未审核"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Text="查看修改意见"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我想通过数据库里面的一个字段的值来控制比如xx=1显示Label1隐藏LinkButton1,xx=2显示LinkButton1,隐藏Label1。
请问后台代码该怎么写??
6 个解决方案
#1
if(xx == 1)
{
Label1.Visible = false; //让Lable1隐藏
else
{
Label1.Visible = true; //让Lable1显示
}
#2
借用
http://bbs.csdn.net/topics/390055673
[code=XML/HTML]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
System.Data.DataRow dr;
dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String)));
for (int i = 0; i < 8; i++)
{
dr = dataTable1.NewRow();
dr[0] = i;
dr[1] = "【孟子E章】" + i.ToString();
dataTable1.Rows.Add(dr);
}
GridView1.DataSource = dataTable1;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function xx(btn) {
b = btn.parentNode;
while (b.tagName != "TR") b = b.parentNode;
b.cells[0].getElementsByTagName("div")[0].style.display = b.cells[0].getElementsByTagName("div")[0].style.display == "none" ? "" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="x" runat="server">
<asp:TextBox ID="replay" runat="server"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="y" runat="server" OnClientClick="xx(this);return false;" Text="显示隐藏测试"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
[/code]
http://bbs.csdn.net/topics/390055673
[code=XML/HTML]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
System.Data.DataRow dr;
dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String)));
for (int i = 0; i < 8; i++)
{
dr = dataTable1.NewRow();
dr[0] = i;
dr[1] = "【孟子E章】" + i.ToString();
dataTable1.Rows.Add(dr);
}
GridView1.DataSource = dataTable1;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function xx(btn) {
b = btn.parentNode;
while (b.tagName != "TR") b = b.parentNode;
b.cells[0].getElementsByTagName("div")[0].style.display = b.cells[0].getElementsByTagName("div")[0].style.display == "none" ? "" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="x" runat="server">
<asp:TextBox ID="replay" runat="server"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="y" runat="server" OnClientClick="xx(this);return false;" Text="显示隐藏测试"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
[/code]
#3
前辈可否给点注释
#4
在GridView控件中的控件,你会发现在页面中它里面的控件Id都会变的...
如果你用JS的话,你运行下看下页面的Id吧.....
后台的话可以在绑定控件时做处理。。。。
如果你用JS的话,你运行下看下页面的Id吧.....
后台的话可以在绑定控件时做处理。。。。
#5
我记得有个事件的··
RowDataBound
这个事件不懂可以不··获取值 然后判断 再处理控件显示与否
RowDataBound
这个事件不懂可以不··获取值 然后判断 再处理控件显示与否
#6
+1
就是按照条件来判断,设置控件的显示与隐藏属性。
#1
if(xx == 1)
{
Label1.Visible = false; //让Lable1隐藏
else
{
Label1.Visible = true; //让Lable1显示
}
#2
借用
http://bbs.csdn.net/topics/390055673
[code=XML/HTML]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
System.Data.DataRow dr;
dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String)));
for (int i = 0; i < 8; i++)
{
dr = dataTable1.NewRow();
dr[0] = i;
dr[1] = "【孟子E章】" + i.ToString();
dataTable1.Rows.Add(dr);
}
GridView1.DataSource = dataTable1;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function xx(btn) {
b = btn.parentNode;
while (b.tagName != "TR") b = b.parentNode;
b.cells[0].getElementsByTagName("div")[0].style.display = b.cells[0].getElementsByTagName("div")[0].style.display == "none" ? "" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="x" runat="server">
<asp:TextBox ID="replay" runat="server"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="y" runat="server" OnClientClick="xx(this);return false;" Text="显示隐藏测试"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
[/code]
http://bbs.csdn.net/topics/390055673
[code=XML/HTML]
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
System.Data.DataRow dr;
dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String)));
for (int i = 0; i < 8; i++)
{
dr = dataTable1.NewRow();
dr[0] = i;
dr[1] = "【孟子E章】" + i.ToString();
dataTable1.Rows.Add(dr);
}
GridView1.DataSource = dataTable1;
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function xx(btn) {
b = btn.parentNode;
while (b.tagName != "TR") b = b.parentNode;
b.cells[0].getElementsByTagName("div")[0].style.display = b.cells[0].getElementsByTagName("div")[0].style.display == "none" ? "" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="x" runat="server">
<asp:TextBox ID="replay" runat="server"></asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="y" runat="server" OnClientClick="xx(this);return false;" Text="显示隐藏测试"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
[/code]
#3
前辈可否给点注释
#4
在GridView控件中的控件,你会发现在页面中它里面的控件Id都会变的...
如果你用JS的话,你运行下看下页面的Id吧.....
后台的话可以在绑定控件时做处理。。。。
如果你用JS的话,你运行下看下页面的Id吧.....
后台的话可以在绑定控件时做处理。。。。
#5
我记得有个事件的··
RowDataBound
这个事件不懂可以不··获取值 然后判断 再处理控件显示与否
RowDataBound
这个事件不懂可以不··获取值 然后判断 再处理控件显示与否
#6
+1
就是按照条件来判断,设置控件的显示与隐藏属性。