我做了动态的gridview,我想把表的主键隐藏了怎么做?
解决方案 »
- 如何解决把XmlDocument.InnerXml放到一个MultiLine的textbox后不换行的问题。
- 为什么图片无法显示
- 安装部署的问题?帮帮忙
- 如何把数据库中的数据分页导入Excel表?
- 水晶报表分组,怎样不显示空白行?
- ====请csdn的朋友帮个忙,问一下这个存储过程为什么返回结果总是为空???
- 数据更新之后的奇怪现象,求教[asp.net/c#+mysql]
- 有了WEB控件;还要HTML控件干什么?——傻傻的问一句。
- iis7.5发布带access数据库的程序出错【在线等】
- 在td中加入id="" runat=“server",后台怎么不能调用呢?
- 如何用这个类System.DirectoryServices.DirectoryEntry操作IIS,在我建立一个站点后,再在这个子站点后建立个子站点
- 关于GridView的鼠标经过背景色变换的问题,离开时换回原来的格式样式!
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
}
}
取值:
GridView.Rows [i].Cells [1].Text
或
<asp:HiddenField ID="Hf_id" Value=' <%#Eval("id")%>' runat="server" />
或
<asp:BoundField DataField="BH" HeaderText="">
<ControlStyle CssClass="hidden" />
<FooterStyle CssClass="hidden"/>
<HeaderStyle CssClass="hidden"/>
<ItemStyle CssClass="hidden"/>
</asp:BoundField>
.hidden
{
display:none;
}
http://topic.csdn.net/u/20090512/16/ae3e5b83-8315-4222-8302-c2755c71b389.html
--既然你的gridview是动态的,那么不绑定datatable中包含主键的那列就可以了。
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "data source=90D57B80B843459;database=Equipment;uid=sa;pwd=;";
sqlcon.Open();
sqlstr = "select 型号,编号,配属单位,运用区段,上线运用日期,设备厂家,状态,ID号 from [liewei1] where 设备名称='列尾主机'order by 编号 Asc "; }
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
myda.Fill(myds); myds.Tables[0].Columns[1].ColumnMapping = MappingType.Hidden; GridView1.DataSource = myds;
GridView1.DataBind();
if (myds.Tables[0].Rows.Count != 0)
{ Label5.Text = "共 " + "" + this.GridView1.PageCount.ToString() + "" + " 页;" + "" + myds.Tables[0].Rows.Count.ToString() + "" + " 条记录";
Label7.Text = "第 " + "" + (this.GridView1.PageIndex+1) + "" + " 页";
LinkButton1.Visible = true;
}
else
{ Label5.Text = "没有找到你要查找的记录 !!!";
Label7.Text = "";
LinkButton1.Visible = false;
}
sqlcon.Close();
DetailsView1.Visible = false;
this.Page_Load(sender, e);
}
打开你那列的属性有下面2个属性
headstyle 取个名字 hidden1
itmestyle 取个名字 hidden2
建个css文件
.hidden1{display:none;}
.hidden2{display:none;}
取值可以用DataKeys
一般都是 a.id=Convert.ToInt32(reader["Id"].ToString());
这句话不要应该就没有了吧
DataKeyNames="ID" AllowPaging="True" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:BoundField DataField="字段1" HeaderText="字段1"
SortExpression="字段1" />
<asp:BoundField DataField="字段2" HeaderText="字段2" />
<asp:BoundField DataField="日期" HeaderText="日期" DataFormatString="{0:d}" />
<asp:BoundField DataField="字段3" HeaderText="字段3" />
<asp:BoundField DataField="字段4" HeaderText="字段4" />
<asp:BoundField DataField="字段5" HeaderText="字段5" />
</Columns>
</asp:GridView>