本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告
================

注会练习软件
http://www.cpasoft.com.cn
我的注会软件官网

http://blog.163.com/abc7105@126/

 

 


哈哈,热爱快“过气”的DELPHI


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:注册会计师(注会)练习软件
日志总数:398
评论数量:116
留言数量:27
访问次数:3273136
建立时间:2005年6月6日




[borland eco 技术]experssionhandle数据源,在datagrid中利用checkbox显示并编辑boolean类型数据
软件技术

吕向阳 发表于 2007/10/8 17:21:08

经过艰苦的探索,今天下午还是做出来了,贴出相关代码 环境为expressionhandle名为ehperson,是person类的全部实例 ,即express表达式person.allinstances 1.aspx文件    <ASP:DataGrid id="DataGrid1" runat="server" width="569px" height="244px" bordercolor="White" borderstyle="Ridge" borderwidth="2px" cellspacing="1" backcolor="White" cellpadding="3" gridlines="None" datasource="<%# ehperson %>" autogeneratecolumns="False" datakeyfield="ExternalId">  <FooterStyle forecolor="Black" backcolor="#C6C3C6"></FooterStyle>  <SelectedItemStyle font-bold="True" forecolor="White" backcolor="#9471DE"></SelectedItemStyle>  <ItemStyle forecolor="Black" backcolor="#DEDFDE"></ItemStyle>  <HeaderStyle font-bold="True" forecolor="#E7E7FF" backcolor="#4A3C8C"></HeaderStyle>  <Columns>    <ASP:BoundColumn datafield="name" sortexpression="name" headertext="name"></ASP:BoundColumn><!--模板开始textbox-->     <asp:templatecolumn>    <itemtemplate>    <asp:textbox  id="text1" runat="server" enabled="False" TEXT='<%# DataBinder.Eval(Container.DataItem,"NAME")%>'></asp:textbox>    </itemtemplate><edititemtemplate>    <asp:textbox  id="text1" runat="server" enabled="TRUE" TEXT='<%# DataBinder.Eval(Container.DataItem,"NAME")%>'></asp:textbox></edititemtemplate>     </asp:templatecolumn> <!--模板结束--> <!--模板开始checkbox-->     <ASP:TemplateColumn headertext="性别">   <ItemTemplate>     <asp:checkbox id="checkbox1" runat="server" enabled="False" checked='<%# DataBinder.Eval(Container.DataItem,"sex")%>'>    </asp:checkbox>   </ItemTemplate>   <EditItemTemplate>  <asp:checkbox id="checkbox1" runat="server" enabled="true" checked='<%# DataBinder.Eval(Container.DataItem,"sex")%>'></asp:checkbox>   </EditItemTemplate>    </ASP:TemplateColumn> <!--模板结束-->     <ASP:EditCommandColumn buttontype="LinkButton" updatetext="Update" canceltext="Cancel" edittext="Edit"></ASP:EditCommandColumn>    <ASP:ButtonColumn text="Delete" commandname="Delete"></ASP:ButtonColumn>  </Columns>  <PagerStyle horizontalalign="Right" forecolor="Black" backcolor="#C6C3C6"></PagerStyle>   </ASP:DataGrid>  有颜色的部分是自定义部分,数据源是expressionhandle,名为ehperson 2在相关的.pas文件中的update事件加入两行代码,一个自定义控件模板一行 红色部分为加入 procedure TWebForm3.DataGrid_UpdateCommand(source: TObject; e: System.Web.UI.WebControls.DataGridCommandEventArgs);var  SourceGrid: DataGrid;  Id: string;  Row: TObject;  Eh: ElementHandle;  ColIndex: Integer;  Col: BoundColumn;begin  SourceGrid := source as DataGrid;  Id := SourceGrid.DataKeys[e.Item.ItemIndex].ToString;  SourceGrid.DataBind(); // To set DataSource  Eh := SourceGrid.DataSource as ElementHandle;  Row := eh.RenderElement(ObjectForId(Id));   for colIndex := 0 to SourceGrid.Columns.Count - 1 do  begin    Col := BoundColumn(SourceGrid.Columns[colIndex]);    if Assigned(Col) and (not Col.ReadOnly) then      eh.SetRenderedElementProperty(row, Col.DataField, (e.Item.Cells[colIndex].Controls[0] as TextBox).Text, true);  end;   eh.SetRenderedElementProperty(row, 'name', (e.Item.FindControl('text1') as textbox).text, true);  eh.SetRenderedElementProperty(row, 'sex', convert.ToString((e.Item.FindControl('checkbox1') as checkbox).Checked), true);   UpdateDatabase;  SourceGrid.EditItemIndex := -1;  DataBind;end; 这里,sex,name分别为ehperson里面的两个字段名.convert.ToString((e.Item.FindControl('checkbox1') as checkbox).Checked) 这里只接受字符表达式,故要转换类型  


阅读全文(1436) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.041 second(s), page refreshed 144793092 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号