Net下有一个类DataGridColumn

作为 DataGrid 控件的不同列类型的基类。

有关此类型全部成员的列表。请參阅 DataGridColumn 成员。

System.Object 

System.Web.UI.WebControls.DataGridColumn 

System.Web.UI.WebControls.BoundColumn 

System.Web.UI.WebControls.ButtonColumn 

System.Web.UI.WebControls.EditCommandColumn 

System.Web.UI.WebControls.HyperLinkColumn 

System.Web.UI.WebControls.TemplateColumn

我们完毕能够写一个继承DataGirdColumn的类,这样就成了。DropDownListColumn,CheckBoxListColumn等。

控件的代码例如以下。

using System; 

using System.Web.UI; 

using System.Web.UI.WebControls ; 

using System.Collections ; 

using System.Data ;

namespace CustomColumn 



/// <summary> 

/// DataGridCustomColumn 的摘要说明。 

/// </summary> 

public class DropDownListColumn :System.Web.UI.WebControls.DataGridColumn 



//数据源 

public DataTable DataSource ; 

//显示的文本字段 

public string DataTextField ; 

// 

public string DataValueField ;

//DataGrid中要绑定的字段

public string DataField ;

public string DataShowField;

public DropDownListColumn() 



// 

// TODO: 在此处加入构造函数逻辑 

//

}

public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) 



base.InitializeCell (cell, columnIndex, itemType); 

switch(itemType) 



case ListItemType.Header : 

cell.Text = this.HeaderText ; 

break;

case ListItemType.Item:case ListItemType.AlternatingItem : 

cell.DataBinding +=new EventHandler(cell_ItemDataBinding); 

break;

case ListItemType.EditItem : 

cell.DataBinding +=new EventHandler(cell_EditItemDataBinding); 

//======================== 

DropDownList drp = new DropDownList(); 

cell.Controls.Add(drp); 

break;



}

private void cell_ItemDataBinding(object sender, EventArgs e) 



TableCell cell =(TableCell)sender ; 

DataGridItem DGI =(DataGridItem)cell.NamingContainer ; 

try 



cell.Text = (DataBinder.Eval(DGI.DataItem,DataShowField)).ToString(); 



catch 



throw new Exception("请设置字段"); 



}

private void cell_EditItemDataBinding(object sender,EventArgs e) 



TableCell cell =(TableCell)sender ; 

DropDownList drp =(DropDownList)cell.Controls[0]; ; 

ListItem item ; 

DataGridItem DGI ; 

try 

{

//================ 

drp.Items.Add(new ListItem("请选择","-1")); 

//

for(int k=0;k<=DataSource.Rows.Count -1;k++) 



DataRow dr = DataSource.Rows[k]; 

item = new ListItem(); 

item.Text = dr[DataTextField].ToString(); 

item.Value = dr[DataValueField].ToString(); 

drp.Items.Add(item); 

}

DGI =(DataGridItem)cell.NamingContainer ;

string Value = DataBinder.Eval(DGI.DataItem,DataField).ToString();

item = drp.Items.FindByValue(Value); 

if(item!=null) 



item.Selected = true; 





catch 



throw new Exception("数据源不正确。"); 

}

}



}

为DataGrid 写一个 DropDownListColumn的更多相关文章

  1. 怎样写一个webpack loader

    div{display:table-cell;vertical-align:middle}#crayon-theme-info .content *{float:left}#crayon-theme- ...

  2. 请写一个php函数,可以接受任意数量的参数

    请写一个php函数,可以接受任意数量的参数 这是一道面试题.怎么写这个函数呢? function fun(......) { } ----------------------------------- ...

  3. 学记:为spring boot写一个自动配置

    spring boot遵循"约定优于配置"的原则,使用annotation对一些常规的配置项做默认配置,减少或不使用xml配置,让你的项目快速运行起来.spring boot的神奇 ...

  4. 自己写一个 jQuery 插件

    我知道这一天终将会到来,现在,它来了. 需求 开发 SharePoint 的 CSOM 应用时,经常需要在网页上输出一些信息. 这种需求和 alert 的弹窗.F12 的断点查看信息的场景是不一样的: ...

  5. 深入浅出React Native 3: 从零开始写一个Hello World

    这是深入浅出React Native的第三篇文章. 1. 环境配置 2. 我的第一个应用 将index.ios.js中的代码全部删掉,为什么要删掉呢?因为我们准备从零开始写一个应用~学习技术最好的方式 ...

  6. 【转】用C写一个简单病毒

    [摘要]在分析病毒机理的基础上,用C语言写了一个小病毒作为实例,用TURBOC2.0实现. [Abstract] This paper introduce the charateristic of t ...

  7. JS入门学习,写一个时钟~

    <!-- 耽搁了几天,于是又继续回到JS的学习了~~ 各种头大,加油吧... --> <!doctype html><html><head> <t ...

  8. JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力。。

      JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力..   小森执行一 ...

  9. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

随机推荐

  1. kill 8080 port on windows

    1. 查找PID netstat -ano | findstr :yourPortNumber 2. kill进程 taskkill /PID typeyourPIDhere /F

  2. D1-mini esp8266的资料备份

    需要更新esp8266库 http://arduino.esp8266.com/stable/package_esp8266com_index.json 下载好即可.

  3. Appium基于python unittest自动化测试并生成html测试报告

    本文基于python单元测试框架unittest完成appium自动化测试,生成基于html可视化测试报告 代码示例: #利用unittest并生成测试报告 class Appium_test(uni ...

  4. PHP——基本使用(二)

    PHP与Apache Apache服务器在接受到客户端请求的时候,根据客户端所请求的文件的类型,然后去问模块能否处理此文件,php作为模块之一有可能可以处理此文件,处理之后将数据再返回给apache, ...

  5. POJ_3565_Ants

    题意:给出N个白点和N个黑点,要求用N条不相交的线段把它们连接起来,其中每条线段恰好连接一个白点和一个黑点,每个点恰好连接到一条线段. 分析:因为有结点黑白两色,我们不难想到构造一个二分图,其中每个白 ...

  6. 安卓app测试之内存监控

    一.通过Dumpsys 来取值 1.adb shell dumpsys meminfo 获取的所有进程的内存信息,以及总内存,剩余内存,使用的内存等信息. 2.想获得某一进程内存的详细信息,在后面加上 ...

  7. Vue指令4:v-on

    监听事件 事件:click\keydown <button v-on:click="greet"></button> 可以简写为  <button @ ...

  8. EasyUI_datagrid

    案例一丶jquery.easyui.min.js:10631 Uncaught TypeError: this.renderEmptyRow is not a function 解决方法:datagr ...

  9. UVA-12333 Revenge of Fibonacci(竖式加法模拟 & 字典树)

    题目: 给出一个斐波那契数字的前缀,问第一个有这个前缀的数字在斐波那契数列中是第几个. 思路: 紫书提示:本题有一定效率要求.如果高精度代码比较慢,可能会超时. 利用滚动数组和竖式加法来模拟斐波那契相 ...

  10. 【模板】51nod 1006 最长公共子序列Lcs

    [题解] dp转移的时候记录一下,然后倒着推出答案即可. #include<cstdio> #include<cstring> #include<algorithm> ...