文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院网络编程Asp.NetDataGrid常见关注问题解决方案
精品推荐
特别推荐
·技巧实例:ASP.NET生成静态页面实现方法
·ASP.NET、JSP及PHP之间的抉择
·.net基础知识错误注意二十二点知识
·asp.net2.0学习历程 菜鸟到中级程序员的飞跃
·.NET基础知识-什么是.NET
·初学C#+ASP.NET+Oracle时积累的备忘点滴
·专家详解:复杂表达式的执行步骤
·asp.net中的加密方法
·DataGrid常见关注问题解决方案
·学习笔记 ASP.NET 5种页面转向法
·ASP.NET网络编程中经常会用到的27个函数集
·ASP.NET之上传文件管理策略
·专家:用.NET动态创建类的实例讲解
·ASP.NET WEB服务和Flash打造MP3播放器
·精通ASP.NET中弹出窗口技术
·asp.net常用代码
·asp.net创建文件夹的IO类的问题
·Asp.Net函数集
·Asp.net cache 简述
·如何最大限度提高.NET的性能 (续)
热点TOP10
·DataTable控件的使用
·ASP.NET上传文件的实例
·ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子!
·asp.net(C#)海量数据表高效率分页算法(易懂,不使用存储过程)
·ASP.NET购物车的实现及结算处理
·在ASP.NET中防止注入攻击[翻译]
·使用ASP.NET2.0的ReportViewer查看RDLC报表
·asp.net程序中最常用的三十三种编程代码
·ASP.NET 2.0的导航控件treeview和menu的实例
·asp.net常用代码
·Lucene.net 实现全文搜索
·在C#后代码里使用IE WEB Control TreeView
·asp.net2.0学习历程 菜鸟到中级程序员的飞跃
·Access 通用数据访问类(asp.net 2.0 c#)
·.Net分页控件发布
·ASP.NET之上传文件管理策略
·AspNetPager分页控件--使用方法
·asp.net 2.0中gridview里嵌套dropdownlist
·手把手教你在Win2003下配置ASP.NET开发环境
·ASP.net在线购物商城系统完全解析

DataGrid常见关注问题解决方案

日期:2007年7月15日 作者:清风网络学院 查看:[大字体 中字体 小字体]



<asp:TemplateColumn HeaderText="genre (database)">
<ItemTemplate>
<asp:Label id=Label1 runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.genre") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id=DropDownList1 runat="server"
DataSource="<%# GetGenreTable() %>"
DataMember="Genre"
DataTextField="genre"
DataValueField="genre"
Width="120px">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
Preselecting an Item in the Drop-Down List
You often want to set the selected item in the drop-down list to match a specific value, usually the value displayed in the cell in display mode. You can do this by setting the SelectedIndex property of the drop-down list to the index of the value to display.

The following example shows a reliable way to do this in a handler for the DataGrid item's ItemDataBound event. This is the correct event to use, because it guarantees that the drop-down list has already been populated, no matter what data source the drop-down list is using.

The trick is in knowing what value to set the drop-down list to. Typically, the value is already available to you either in the current item (being displayed) or in the DataItem property of the current item, which returns a DataRowView object containing the current record. Once you have the value, you can use the DropDownList control's FindByText or FindByValue method to locate the correct item in the list; you can then use the item's IndexOf property to return the index.

' Visual Basic
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentgenre As String = CType(drv("genre"), String)
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl("DropDownList1"), DropDownList)
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(currentgenre))
End If
End Sub

// C#
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.EditItem){
DataRowView drv = (DataRowView) e.Item.DataItem;
String currentgenre = drv["genre"].ToString();

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] 下一页 




上一篇:自己写的一个简单ASP调用存储过程查询

下一篇:使用ASP与JAVASCRIPT配合实现多个复选框数据关联显示

DataGrid常见关注问题解决方案 相关文章:
·XP系统运行慢?小编自用7招解决
·《边看边打赚大奖--迅雷宽频》部分问题及答案
·不用重装XP系统就可以解决全部故障
·校园网组建方案
·施工与工程组织方案
·全面解决Generic host process for win32 services遇到问题需要关闭
·经典常见计算机密码破解实用手册
·[综合]召唤兽常见技能资质表(最新修补完整版)
·国内大学校园网网络建设方案参考
·外挂 录象 网站 举报方案最新教程_QQ堂
DataGrid常见关注问题解决方案 相关软件:
·网络常见问题与故障1000例
·成功少儿培养方案(上中下)高清晰PDF电子书
·有关毛泽东的一些问题解答(不完整版)
·中东问题的历史根源
·每天问自己十个问题
·动网先锋系统集成方案大全
·《常见皮肤性病诊断与治疗》
·生命问题
·百度知道 1850个经典问题
·SmartGrid表格控件 for Asp.Net(Web Grid,DataGrid) V2.0 For VS2005

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.vipcn.net
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.vipcn.net All Rights Reserved. 鄂ICP备05000083号Powered by:viphot