DataGrid DropDownList 相关处理函数
2006-04-21 11:11
375 查看
#region DataGrid 相关处理函数
/// <summary>
/// 根据绑定的列的名字,获得在DataGrid中的Index值
/// </summary>
/// <param name="dgcc">DataGridColumnCollection</param>
/// <param name="FieldName">绑定列的字段名</param>
/// <returns>Int >0 在DataGrid中的Index,-1:没有找到</returns>
public static int DataGrid_FindColumnIndex(DataGridColumnCollection dgcc, string FieldName)
{
string temp;
DataGridColumn column;
BoundColumn boundColumn;
int i;
FieldName = FieldName.ToUpper();
for(i=0;i<dgcc.Count;i++)
{
column = dgcc[i];
if(column is BoundColumn)
{
boundColumn = (BoundColumn)column;
temp = boundColumn.DataField.ToUpper();
if(temp==FieldName)
return i;
}
}
return -1;
}
/// <summary>
/// 根据绑定的列的名字,获得在DataGrid中的Index值
/// </summary>
/// <param name="dg">DataGrid</param>
/// <param name="FieldName">绑定列的字段名</param>
/// <returns>Int >0 在DataGrid中的Index,-1:没有找到</returns>
public static int DataGrid_FindDataGridColumnIndex(DataGrid dg, string FieldName)
{
string temp;
DataGridColumn column;
BoundColumn boundColumn;
int i;
FieldName = FieldName.ToUpper();
for(i=0;i<dg.Columns.Count;i++)
{
column = dg.Columns[i];
if(column is BoundColumn)
{
boundColumn = (BoundColumn)column;
temp = boundColumn.DataField.ToUpper();
if(temp==FieldName)
return i;
}
}
return -1;
}
//当DataGrid中记录数发生改变时,避免越界
/// <summary>
/// 获得DataGrid的当前页数
/// </summary>
/// <param name="currentPageIndex">原来DataGrid的当前页码</param>
/// <param name="pageSize">DataGrid每页显示的记录数</param>
/// <param name="rowCount">DataGrid的记录数</param>
/// <returns>返回处理后的页码</returns>
public static int DataGrid_GetCurrentPageIndex(int currentPageIndex,int pageSize,int rowCount)
{
int pageIndex;
if(pageSize==0) return 1;
pageIndex=(rowCount-1)/pageSize;
if(pageIndex < 0) return 0; //当rowCount=0时,会返回-1,页面出错
if(currentPageIndex > pageIndex)
return pageIndex;
else
return currentPageIndex;
}
/*
* 使用示例代码
*
* /// <summary>
/// 邦定列表
/// </summary>
private void BindDataSource()
{
try
{
IDataGrid1.DataSource = DS;
IDataGrid1.PageSize = 10;
IDataGrid1.CurrentPageIndex = DataGrid_GetCurrentPageIndex(IDataGrid1.CurrentPageIndex,IDataGrid1.PageSize,DS.Tables[0].Rows.Count);
IDataGrid1.DataBind();
}
catch
{;}
}
/// <summary>
/// 分页操作
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void IDataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
IDataGrid1.CurrentPageIndex = e.NewPageIndex;
BindDataSource();
}
/// <summary>
/// 选择操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void IDataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int idIndex = DataGrid_FindColumnIndex(IDataGrid1.Columns,"ID");
if(idIndex >= 0 )
{
Response.Redirect("Default.aspx?ID=" + IDataGrid1.SelectedItem.Cells[idIndex].Text,true);
}
}
*
* */
#endregion
#region DropDownList 相关处理函数
/// <summary>
/// 根据绑定的列的Value值,获得在DropDownList中的Index值
/// </summary>
/// <param name="lic">ListItemCollection</param>
/// <param name="bandValue">绑定列的字段名</param>
/// <returns>Int >0 在DropDownList中的Index,-1:没有找到</returns>
public static int DropDownList_FindListItemIndex(ListItemCollection lic, string bandValue)
{
string temp;
bandValue = bandValue.ToUpper();
for(int i=0;i<lic.Count;i++)
{
temp = lic[i].Value.ToUpper();
if(temp == bandValue)
{
return i;
}
}
return -1;
}
/*
* 使用示例
*
* /// <summary>
/// 获取DropDownList列表SelectIndex
/// </summary>
/// <param name="listItemCol"></param>
/// <param name="sValue"></param>
/// <returns></returns>
private int BindDropDownListSelectIndex(ListItemCollection listItemCol, string sValue)
{
int DDLSelectIndex = DropDownList_FindListItemIndex(listItemCol,sValue);
if(DDLSelectIndex != -1)
{
return DDLSelectIndex;
}
else
{
return 0;
}
}
*
* */
#endregion
/// <summary>
/// 根据绑定的列的名字,获得在DataGrid中的Index值
/// </summary>
/// <param name="dgcc">DataGridColumnCollection</param>
/// <param name="FieldName">绑定列的字段名</param>
/// <returns>Int >0 在DataGrid中的Index,-1:没有找到</returns>
public static int DataGrid_FindColumnIndex(DataGridColumnCollection dgcc, string FieldName)
{
string temp;
DataGridColumn column;
BoundColumn boundColumn;
int i;
FieldName = FieldName.ToUpper();
for(i=0;i<dgcc.Count;i++)
{
column = dgcc[i];
if(column is BoundColumn)
{
boundColumn = (BoundColumn)column;
temp = boundColumn.DataField.ToUpper();
if(temp==FieldName)
return i;
}
}
return -1;
}
/// <summary>
/// 根据绑定的列的名字,获得在DataGrid中的Index值
/// </summary>
/// <param name="dg">DataGrid</param>
/// <param name="FieldName">绑定列的字段名</param>
/// <returns>Int >0 在DataGrid中的Index,-1:没有找到</returns>
public static int DataGrid_FindDataGridColumnIndex(DataGrid dg, string FieldName)
{
string temp;
DataGridColumn column;
BoundColumn boundColumn;
int i;
FieldName = FieldName.ToUpper();
for(i=0;i<dg.Columns.Count;i++)
{
column = dg.Columns[i];
if(column is BoundColumn)
{
boundColumn = (BoundColumn)column;
temp = boundColumn.DataField.ToUpper();
if(temp==FieldName)
return i;
}
}
return -1;
}
//当DataGrid中记录数发生改变时,避免越界
/// <summary>
/// 获得DataGrid的当前页数
/// </summary>
/// <param name="currentPageIndex">原来DataGrid的当前页码</param>
/// <param name="pageSize">DataGrid每页显示的记录数</param>
/// <param name="rowCount">DataGrid的记录数</param>
/// <returns>返回处理后的页码</returns>
public static int DataGrid_GetCurrentPageIndex(int currentPageIndex,int pageSize,int rowCount)
{
int pageIndex;
if(pageSize==0) return 1;
pageIndex=(rowCount-1)/pageSize;
if(pageIndex < 0) return 0; //当rowCount=0时,会返回-1,页面出错
if(currentPageIndex > pageIndex)
return pageIndex;
else
return currentPageIndex;
}
/*
* 使用示例代码
*
* /// <summary>
/// 邦定列表
/// </summary>
private void BindDataSource()
{
try
{
IDataGrid1.DataSource = DS;
IDataGrid1.PageSize = 10;
IDataGrid1.CurrentPageIndex = DataGrid_GetCurrentPageIndex(IDataGrid1.CurrentPageIndex,IDataGrid1.PageSize,DS.Tables[0].Rows.Count);
IDataGrid1.DataBind();
}
catch
{;}
}
/// <summary>
/// 分页操作
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void IDataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
IDataGrid1.CurrentPageIndex = e.NewPageIndex;
BindDataSource();
}
/// <summary>
/// 选择操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void IDataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int idIndex = DataGrid_FindColumnIndex(IDataGrid1.Columns,"ID");
if(idIndex >= 0 )
{
Response.Redirect("Default.aspx?ID=" + IDataGrid1.SelectedItem.Cells[idIndex].Text,true);
}
}
*
* */
#endregion
#region DropDownList 相关处理函数
/// <summary>
/// 根据绑定的列的Value值,获得在DropDownList中的Index值
/// </summary>
/// <param name="lic">ListItemCollection</param>
/// <param name="bandValue">绑定列的字段名</param>
/// <returns>Int >0 在DropDownList中的Index,-1:没有找到</returns>
public static int DropDownList_FindListItemIndex(ListItemCollection lic, string bandValue)
{
string temp;
bandValue = bandValue.ToUpper();
for(int i=0;i<lic.Count;i++)
{
temp = lic[i].Value.ToUpper();
if(temp == bandValue)
{
return i;
}
}
return -1;
}
/*
* 使用示例
*
* /// <summary>
/// 获取DropDownList列表SelectIndex
/// </summary>
/// <param name="listItemCol"></param>
/// <param name="sValue"></param>
/// <returns></returns>
private int BindDropDownListSelectIndex(ListItemCollection listItemCol, string sValue)
{
int DDLSelectIndex = DropDownList_FindListItemIndex(listItemCol,sValue);
if(DDLSelectIndex != -1)
{
return DDLSelectIndex;
}
else
{
return 0;
}
}
*
* */
#endregion
相关文章推荐
- python文件处理相关函数
- C语言中,时间调用处理的相关函数介绍
- Oracle 存储过程总结 二、字符串处理相关函数
- PHP数组的相关处理函数1
- php字符串处理函数相关操作
- PHP处理文件和操作系统的相关函数
- PHP会话处理相关函数介绍
- C# EXCEL表格处理相关函数
- 处理中文字符相关的函数
- PHP扩展之图像处理2——Gmagick库使用示例及相关类和函数
- php学习笔记(六)数组及其相关处理函数
- PHP会话处理相关函数介绍
- Win32 路径处理相关函数
- Matlab 图像处理相关函数命令大全
- PHP数字处理相关函数持续记录
- Win32 路径处理相关函数
- PHP GD库相关图像生成和处理函数
- MATLAB图像处理相关函数 非常有用
- [转] MATLAB图像处理相关函数 非常有用
- 字符串相关(字符串数组,字符串处理相关函数、自实现函数)