请教各位大哥,datagrid中编辑按钮如何应用样式?

zyq1215 2004-10-26 02:34:56
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="上传" HeaderText="编辑" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>

请教三种按钮怎样应用样式?
...全文
169 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
e.Item.Cells[4].Controls是一个控件的集合,
根据实践的经验一般有这样的规律:
如果是按钮列,就是Controls[0],如果按钮列中同时出现“更新”“取消”,那么就是Controls[0]、[2];

如果是模板列嵌套的服务器端控件,那么就是Controls[1]、[3]、[5]、......
除此之外没什么可说的了
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
Button btnCancel = (Button)e.Item.Cells[4].Controls[2];可以了,多谢,多谢
能不能请教为什么不是[1]呢?
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
谢谢暴大哥,我再试试
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
取消键是第4列的第2控件呀,应该是(Button)e.Item.Cells[4].Controls[1]呀!
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
... sorry ... 试试Button btnCancel = (Button)e.Item.Cells[4].Controls[2];
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
哦,试试Button btnCancel = (Button)e.Item.Cells[4].Controls[3];
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
不是样式的问题
Button btnCancel = (Button)e.Item.Cells[4].Controls[1]; 报错

Button btnUpdate = (Button)e.Item.Cells[4].Controls[0]; 则可以,怎么回事?
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
if(e.Item.ItemType==ListItemType.EditItem)
{
Button btnUpdate = (Button)e.Item.Cells[4].Controls[0]; //第四列
btnUpdate.CssClass = "button";
Button btnCancel = (Button)e.Item.Cells[5].Controls[0]; //第五列
btnCancel.CssClass = "button";
}

Button btnCancel = (Button)e.Item.Cells[4].Controls[1]; 报错,
怎么回事?
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
你有没有使用样式css?
如果有,那么btnUpdate.CssClass = "你定义的一种样式";
如果没有,就要一个一个的设置了,例如
btnUpdate.BackColor = System.Drawing.Color.Yellow;
btnUpdate.ForeColor = System.Drawing.Color.Red;
btnUpdate.Style.Add("BORDER-RIGHT","black 1px double");//右边界
................
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
if(e.Item.ItemType==ListItemType.EditItem)
{
Button btnUpdate = (Button)e.Item.Cells[4].Controls[0];
btnUpdate.CssClass = "button";
Button btnCancel = (Button)e.Item.Cells[4].Controls[1];
btnCancel.CssClass = "button";
}

Button btnCancel = (Button)e.Item.Cells[4].Controls[1]; 报错,
怎么回事?
icyer 2004-10-26
  • 打赏
  • 举报
回复
btnUpdate.Attributes.Add("Style", "button");
其他类似
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
Button btnUpdate = (Button)e.Item.Cells[0].Controls[0]; //假设是第一列
btnUpdate.Style = "样式名";
可以

Button btnCancel = (Button)e.Item.Cells[0].Controls[1];
btnCancel.Style ="样式名";
不行

怎么回事?
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
icyer大哥和暴大哥:
btnUpdate.Style = "button"
编译不了,怎么办?
huoming1978 2004-10-26
  • 打赏
  • 举报
回复
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="上传" HeaderText="编辑" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
你这样就是统一的呀.
Eddie005 2004-10-26
  • 打赏
  • 举报
回复
icyer() 完全正确
zyq1215 2004-10-26
  • 打赏
  • 举报
回复
但我想用PushButton以求统一
icyer 2004-10-26
  • 打赏
  • 举报
回复
在ItemDataBound中设置:
if (e.Item.ItemType == ListItemType.Edit)
{
Button btnUpdate = (Button)e.Item.Cells[0].Controls[0]; //假设是第一列
btnUpdate.Style = "样式名";
Button btnCancel = (Button)e.Item.Cells[0].Controls[1];
btnCancel.Style = "...";
}
else if (e.Item.ItemIndex >= 0)
{
Button btnEdit = (Button)e.Item.Cells[0].Controls[0];
btnEdit.Style = "...";
}

try it.
bitsbird 2004-10-26
  • 打赏
  • 举报
回复
ButtonType="LinkButton"

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧