社区
C#
帖子详情
DataGrid中的按扭列
sdfdsfjl011
2005-08-01 05:40:49
在DataGrid的属性中选择"列",再选择按扭列中的"编辑 更新 取消",在运行时的网页中点击编辑无任何效果,是不是还要写代码,如果有是在哪里写,怎么写.
...全文
78
6
打赏
收藏
DataGrid中的按扭列
在DataGrid的属性中选择"列",再选择按扭列中的"编辑 更新 取消",在运行时的网页中点击编辑无任何效果,是不是还要写代码,如果有是在哪里写,怎么写.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
silverseven7
2005-08-01
打赏
举报
回复
#region datagrid event
/// <summary>
/// page index change
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void dg_Exec_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid pageindex change event start");
dg_Exec.EditItemIndex = -1;
dg_Exec.SelectedIndex = -1;
dg_Exec.CurrentPageIndex = e.NewPageIndex;
BindData(dg_Exec);
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid pageindex change event end");
}
/// <summary>
/// dg sort
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void dg_Exec_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid sort event start");
this.dg_Exec.CurrentPageIndex = 0;
this.dg_Exec.EditItemIndex = -1 ;
this.SetDropDownListStatus(1);
if(hid_SortField.Value == e.SortExpression)
{
hid_SortType.Value = (hid_SortType.Value == ""? " Desc":"");
}
else
{
hid_SortField.Value = e.SortExpression;
hid_SortType.Value = "";
}
BindData(dg_Exec);
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid sort event end");
}
private void dg_Exec_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType lit = e.Item.ItemType;
switch(lit)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
ImageButton btn_DgDelete = (ImageButton)e.Item.FindControl("btn_DgDelete");
ComJScript.Confirm(btn_DgDelete,ComLocalDiff.GetMessageById("0715",UserInfo.LangCode));
break;
case ListItemType.EditItem:
// binding dropdownList to dataGrid
DataRowView drv = (DataRowView)e.Item.DataItem ;
DropDownList dpl_DGStatCode = (DropDownList)e.Item.FindControl("dpl_DGStatCode");
if(!Convert.IsDBNull(drv) & drv != null)
{
dpl_DGStatCode.SelectedIndex = dpl_DGStatCode.Items.IndexOf(dpl_DGStatCode.Items.FindByValue(drv["STAT_CODE"].ToString()));
}
break;
}
}
private void dg_Exec_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strCompany ;
string strLocation ;
string strEmpnum ;
string strStat ;
string strUid = UserInfo.UID;
switch(e.CommandName)
{
// delete data form database
case "Delete":
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid delete command start");
strCompany = e.Item.Cells[2].Text;
strLocation = e.Item.Cells[3].Text;
strEmpnum = e.Item.Cells[6].Text;
strStat = e.Item.Cells[5].Text;
try
{
OtForExecDB.UpdateData("Delete",strCompany,strLocation,strEmpnum,strStat,strUid);
dg_Exec.CurrentPageIndex = 0;
dg_Exec.EditItemIndex = -1;
this.Session["OtForExec"] =null;
SetHidSearchCondition();
ComJScript.AlertNormal(this,ComLocalDiff.GetMessageById("0714",UserInfo.LangCode));
BindData(dg_Exec);
}
catch(Exception ex)
{
ComLogOutput.WriteLogFile(ex);
this.lbl_Err.Text = ComLocalDiff.GetMessageById("0001",UserInfo.LangCode);
return;
}
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid delete command end");
break;
//set datagrid status is edit
case "Edit":
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid edit command start");
this.dg_Exec.EditItemIndex = e.Item.ItemIndex;
SetDropDownListStatus(0);
BindData(dg_Exec);
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid edit command end");
break;
//update data
case "OK":
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid update command start");
strStat = ((DropDownList)e.Item.FindControl("dpl_DGStatCode")).SelectedItem.Value;
string strLanguage = UserInfo.LangCode;
try
{
strCompany = e.Item.Cells[2].Text;
strLocation = e.Item.Cells[3].Text;
strEmpnum = e.Item.Cells[6].Text;
DateTime strUpdt = DateTime.Parse(e.Item.Cells[7].Text);
strStat = ((DropDownList)e.Item.FindControl("dpl_DGStatCode")).SelectedItem.Value;
OtForExecDB.CheckEmpExist(strCompany,strLocation,strEmpnum,strStat,"Update",strLanguage,strUpdt);
OtForExecDB.UpdateData("Update",strCompany,strLocation,strEmpnum,strStat,strUid);
dg_Exec.CurrentPageIndex = 0;
dg_Exec.EditItemIndex = -1;
this.Session["OtForExec"] =null;
ComJScript.AlertNormal(this,ComLocalDiff.GetMessageById("0713",UserInfo.LangCode));
SetDropDownListStatus(1);
this.hid_Exception.Value="*";
BindData(dg_Exec);
}
catch(ApplicationException appex)
{
ComLogOutput.WriteLogFile(appex);
this.lbl_Err.Text = appex.Message;
return;
}
catch(Exception ex)
{
ComLogOutput.WriteLogFile(ex);
this.lbl_Err.Text = ComLocalDiff.GetMessageById("0001",UserInfo.LangCode);
return;
}
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid update command end");
break;
//cancel update operate
case "Cancel":
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid cancle command start");
dg_Exec.Columns[1].Visible=true;
this.dg_Exec.EditItemIndex = -1 ;
SetDropDownListStatus(1);
BindData(dg_Exec);
ComLogOutput.WriteLogFile("dsp_OtForExec.aspx datagrid cancle command end");
break;
}
}
silverseven7
2005-08-01
打赏
举报
回复
<asp:datagrid id="dg_Exec" CssClass="DATAGRID_DEFAULT" Width="100%" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" Runat="server">
<AlternatingItemStyle CssClass="Result_DG_AlternatingItemStyle"></AlternatingItemStyle>
<ItemStyle CssClass="Result_DG_ItemStyle"></ItemStyle>
<HeaderStyle Wrap="False" HorizontalAlign="Center" CssClass="Result_DG_HeaderStyle"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Edit">
<HeaderStyle HorizontalAlign="Center" Width="8%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="8%"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="btn_DgEdit" CausesValidation="false" runat="server" CommandName="Edit" ImageUrl="images/edititem.gif" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="btn_DgOK" CausesValidation="false" runat="server" CommandName="OK" ImageUrl="images/save.gif" />
<asp:ImageButton id="btn_DgCancel" runat="server" CausesValidation="false" CommandName="Cancel" ImageUrl="images/Exit.gif" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Delete">
<HeaderStyle HorizontalAlign="Center" Width="7%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="7%"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="btn_DgDelete" runat="server" CausesValidation="false" CommandName="Delete" ImageUrl="images/delete.gif" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="CMPY_CODE" ItemStyle-HorizontalAlign="Center" ReadOnly="True" HeaderText="CMPY_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="LOCN_CODE" ItemStyle-HorizontalAlign="Center" ReadOnly="True" HeaderText="LOCN_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="EMP_NAME" SortExpression="EMP_NAME" ItemStyle-HorizontalAlign="Center"
ReadOnly="True" HeaderText="EMP_NAME"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="STAT_CODE" HeaderText="Exception Type">
<HeaderStyle HorizontalAlign="Center" Width="20%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="20%"></ItemStyle>
<ItemTemplate>
<asp:Label Width="100%" Runat="server" ID="lbl_STAT_CODE" text='<%#DataBinder.Eval(Container, "DataItem.STAT_CODE")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dpl_DGStatCode" Width="100%" Runat="server">
<asp:ListItem Value="I">Included</asp:ListItem>
<asp:ListItem Value="E">Excluded</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="EMP_NUM" Visible="False" ReadOnly="True" HeaderText="EMP_NUM"></asp:BoundColumn>
<asp:BoundColumn DataField="UPDT_DATE" Visible="False" ReadOnly="True" HeaderText="UPDT_DATE"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="left" Position="Top" Mode="NumericPages"></PagerStyle>
</asp:datagrid><asp:datagrid id="dg_ExecShow" CssClass="DATAGRID_DEFAULT" Width="100%" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" Runat="server">
<AlternatingItemStyle CssClass="Result_DG_AlternatingItemStyle"></AlternatingItemStyle>
<ItemStyle CssClass="Result_DG_ItemStyle"></ItemStyle>
<HeaderStyle Wrap="False" HorizontalAlign="Center" CssClass="Result_DG_HeaderStyle"></HeaderStyle>
<Columns>
<ASP:TEMPLATECOLUMN HEADERTEXT="Import" ItemStyle-HorizontalAlign="Center">
<HeaderStyle Wrap="False" />
<ITEMTEMPLATE>
<ASP:CHECKBOX ID="dg_chkImport" RUNAT="server" />
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
<asp:BoundColumn DataField="CMPY_CODE" ItemStyle-HorizontalAlign="Center" ReadOnly="True" HeaderText="CMPY_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="LOCN_CODE" ItemStyle-HorizontalAlign="Center" ReadOnly="True" HeaderText="LOCN_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="EMP_NAME" SortExpression="EMP_NAME" ItemStyle-HorizontalAlign="Center"
ReadOnly="True" HeaderText="EMP_NAME"></asp:BoundColumn>
<asp:BoundColumn DataField="EMP_NUM" Visible="False" ReadOnly="True" HeaderText="EMP_NUM"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="left" Position="Top" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
conan1211
2005-08-01
打赏
举报
回复
如果你用的是"编辑 更新 取消"的话
前台和后台虽都是必须的
但前台的代码也可以放在后台来完成
那就要用到控件的Attributes属性了
conan1211
2005-08-01
打赏
举报
回复
这两个是必须同时都有的
如果你用的是"编辑 更新 取消"的话
如果你用的是模板列的话
就只用可以在模板列里放个Button再设置它的CommendName
然后就可以直接在后台写代码了
这样就不用在HTML端写那些烦人的东东了
sdfdsfjl011
2005-08-01
打赏
举报
回复
HTML的我已经知道了,能不能在后台写
conan1211
2005-08-01
打赏
举报
回复
如果是用那个东东的话
在HTML端和代码端都要写代码比较麻烦
还不如用模板列
在里面加上Button就好处理多了(个人感觉)
Easyui
Datagrid
自定义按钮列(最后面的操作列)
做项目的时候因为需求,要在表格的最后添加一列操作列,easyUI貌似没有提供这种功能,下面我们来自定义按钮列,具体实现代码,大家参考下本文吧
EasyUI的
DataGrid
每行数据添加操作按钮的实现代码
今天做项目的时候,想在easyui的
datagrid
每一列数据后边都加上一个操作按钮,怎么实现此功能呢?下面小编给大家带来了EasyUI的
DataGrid
每行数据添加操作按钮的实现代码,需要的朋友参考下吧
Java整合JQueryEasyUI详解
本门课程的技术呢比较陈旧,视频
中
的有些杂音,如果你们公司用不着这个技术你就别学了,因为这技术确实已经挺老的了,可以学一些新的前端技术,例如BootStrap或者Vue,或者angularJS啦什么都可以. 课程目标: 1.熟练掌握...
Flex
dataGrid
表头添加按钮
老外做的功能有点复杂,我整理了其
中
一个简单的效果,在表头上加一个按钮。扩展的话可以实现数据过滤,或者下拉动态隐藏指定列(灵感都来自extjs呵呵)。 也可以在此下载:...
WPF在
dataGrid
中
添加CheckBox支持单选,多选,全选功能
项目
中
用到
DataGrid
, 需要在第一列添加checkbox, 可以多选、全选。 其
中
涉及的概念DataTemplate,
DataGrid
CellStyle,
DataGrid
CellControlTemplate,Binding, OnPropertyChanged等。
C#
110,536
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章