遇到一个很棘手的问题,我是通过程序动态把数据库绑定DataGrid的,想要动态隐藏某列,怎么不起作用啊,还有为什么DataGrid不能拖动列的宽度啊,有时后字段的内容太多,把DataGrid拉伸的太难看了,能做到字显示一部分内容,鼠标放上区显示全部么?请各位大虾帮帮忙解决,非常感谢!
解决方案 »
- GridView怎么不出数据呢?
- 请问在框架中如何实现,两个按钮的结果分区显示?
- [求救] ASP.NET被攻击了
- 如何得到datagrid合计?
- 初学问题:开发一个简单的ASP.NET操作数据库的页面
- 这样写为什么不能打开页面,要怎么样写,而且页面的属性是根据设定好的一样?
- Graphics.DrawString写字时,怎么调节字得粗细?
- 又一个iframe的小问题,急!~~~~~~~~~~~~~~
- 刚学ASP。NET 请问各位大哥有没好的例子学TREE控件的用法啊!!!!!!!
- 谁有基于asp.net(c#版)的聊天室源代码或文档 (50分全给)
- 100分跪求VB的EXCL导出程序
- freetextbox怎么老是闪啊
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If e.Item.Cells(0).Text.Length > 26 Then
e.Item.Cells(0).Attributes.Add("Title", e.Item.Cells(0).Text)
e.Item.Cells(0).Text = e.Item.Cells(0).Text.Substring(0, 26) + "…"
End If
End If
End Sub
完善一下,对于较长的字符串要截断时,可以动态添加一个HyperLink,设置链接,弹出新的页面进行显示,也可以设置ToolTip为截断前的字符串,这样当鼠标划过时也可以显示....
SqlDataAdapter sqlda=new SqlDataAdapter (strsql,sqlcnn);
sqlcnn.Open ();
DataSet ds=new DataSet ();
sqlda.Fill (ds);
DataView dv=new DataView (ds.Tables[0]);
DataGrid1.DataSource =dv;
DataGrid1.DataBind ();
DataGrid1.Columns[0].Visible=false;
sqlcnn.Close ();
if(e.Item.Cells[9].Text.Length>25)
e.Item.Cells[9].Text = e.Item.Cells[9].Text.Trim().ToString().Substring(0,25);
else
e.Item.Cells[9].Text = e.Item.Cells[9].Text.Trim().ToString();
SqlDataAdapter sqlda=new SqlDataAdapter (strsql,sqlcnn);
sqlcnn.Open ();
DataSet ds=new DataSet ();
sqlda.Fill (ds);
DataView dv=new DataView (ds.Tables[0]);
DataGrid1.DataSource =dv;
DataGrid1.DataBind ();
DataGrid1.Columns[0].Visible=false;
sqlcnn.Close ();
this.DataGrid1.DataBind();
//将DateGrid的第三列设置为隐藏列。
this.DataGrid1.Columns[2].Visible = false;
获得隐藏列的值:
private void DataGrid1_ItemCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//获得DateGrd中隐藏列的值。
TableCell myCell = e.Item.Cells[2];
string row = myCell.Text.ToString();
//判断点击的哪个按钮。
if(e.CommandName=="Select")
//将获得的隐藏列的值作为参数,传递到UPDATE页面。
Response.Redirect("UPDATE.aspx?Cnt=" + row );
}
搞定。
this.DataGrid1.DataBind();
//将DateGrid的第三列设置为隐藏列。
this.DataGrid1.Columns[2].Visible = false;
获得隐藏列的值:
private void DataGrid1_ItemCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//获得DateGrd中隐藏列的值。
TableCell myCell = e.Item.Cells[2];
string row = myCell.Text.ToString();
//判断点击的哪个按钮。
if(e.CommandName=="Select")
//将获得的隐藏列的值作为参数,传递到UPDATE页面。
Response.Redirect("UPDATE.aspx?Cnt=" + row );
}不行啊,我的列全没了