婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > asp.net中GridView和DataGrid相同列合并實現代碼

asp.net中GridView和DataGrid相同列合并實現代碼

熱門標簽:保山電話外呼管理系統怎么用 太原外呼電銷機器人費用 東莞語音電銷機器人排名 朝陽市地圖標注 淘寶地圖標注如何做 蘇州銷售外呼系統預算 電話機器人廣告話術 使用智能電話機器人違法嗎 外呼系統用員工身份證
(一)普通列
復制代碼 代碼如下:

/// summary>
/// Gridview列的合并(普通列,不包含模板列)
/// 注意:1.GridView在綁定的時候進行分組和排序,才能讓相同的行放在一起
/// 2.方法應用的時機,應該在Gridview的DataBound事件中使用
/// /summary>
/// param name="gv">需要合并的GridView對象/param>
/// param name="columnIndex">所要合并列的索引/param>
public static void UnitCell(GridView gv, int columnIndex)
{
int i = 0; //當前行數
string lastType = string.Empty; //當前判斷是否合并行對應列的值
int lastCell = 0; //判斷最后一個相同值的行的索引
if (gv.Rows.Count > 0)
{
lastType = gv.Rows[0].Cells[columnIndex].Text.ToString();
gv.Rows[0].Cells[columnIndex].RowSpan = 1;
lastCell = 0;
}
for (i = 1; i gv.Rows.Count; i++)
{
if (gv.Rows[i].Cells[columnIndex].Text == lastType)
{
gv.Rows[i].Cells[columnIndex].Visible = false;
gv.Rows[lastCell].Cells[columnIndex].RowSpan++;
}
else
{
lastType = gv.Rows[i].Cells[columnIndex].Text.ToString();
lastCell = i;
gv.Rows[i].Cells[columnIndex].RowSpan = 1;
}
}
}
/// summary>
/// DataGrid列的合并(普通列,不包含模板列)
/// 注意:1.DataGrid在綁定的時候進行分組和排序,才能讓相同的行放在一起
/// 2.方法應用的時機,應該在DataGrid的DataBound事件中使用
/// /summary>
/// param name="dg">需要合并的DataGrid對象/param>
/// param name="columnIndex">所要合并列的索引/param>
public static void UnitCell_T(DataGrid dg, int columnIndex)
{
int i = 0; //當前行數
string lastType = string.Empty; //當前判斷是否合并行對應列的值
int lastCell = 0; //判斷最后一個相同值的行的索引
if (dg.Items.Count> 0)
{
lastType = dg.Items[0].Cells[columnIndex].Text.ToString();
dg.Items[0].Cells[columnIndex].RowSpan = 1;
lastCell = 0;
}
for (i = 1; i dg.Items.Count; i++)
{
if (dg.Items[i].Cells[columnIndex].Text == lastType)
{
dg.Items[i].Cells[columnIndex].Visible = false;
dg.Items[lastCell].Cells[columnIndex].RowSpan++;
}
else
{
lastType = dg.Items[i].Cells[columnIndex].Text.ToString();
lastCell = i;
dg.Items[i].Cells[columnIndex].RowSpan = 1;
}
}
}

(二)模板列
復制代碼 代碼如下:

/// summary>
/// Gridview列的合并(模板列)
/// /summary>
/// param name="gv">需要合并的GridView對象/param>
/// param name="columnIndex">所要合并列的索引/param>
/// param name="lblName">模板列對象的ID/param>
public static void UnitCell(GridView gv, int columnIndex, string lblName)
{
int i = 0; //當前行數
string lastType = string.Empty; //當前判斷是否合并行對應列的值
int lastCell = 0; //判斷最后一個相同值的行的索引
if (gv.Rows.Count > 0)
{
lastType = (gv.Rows[0].Cells[columnIndex].FindControl(lblName) as Label).Text;
gv.Rows[0].Cells[columnIndex].RowSpan = 1;
lastCell = 0;
}
for (i = 1; i gv.Rows.Count; i++)
{
if ((gv.Rows[i].Cells[columnIndex].FindControl(lblName) as Label).Text == lastType)
{
gv.Rows[i].Cells[columnIndex].Visible = false;
gv.Rows[lastCell].Cells[columnIndex].RowSpan++;
}
else
{
lastType = (gv.Rows[i].Cells[columnIndex].FindControl(lblName) as Label).Text.ToString();
lastCell = i;
gv.Rows[i].Cells[columnIndex].RowSpan = 1;
}
}
}

(三)在DataBound事件中調用即可。

在GridView或DataGrid中顯示固定寬度的列

默認情況下,Gridview和Datagrid控件依據它們的內容自動調整列大小。要為列指定固定寬度,設置每個Tablecell對象的Width屬性并設置Wrap屬性為False。下面的例子顯示了如何通過使用DataGrid控件去做。
復制代碼 代碼如下:

rotected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
ListItemType lit = e.Item.ItemType;
if (lit == ListItemType.Header)
{
for (int i = 0; i e.Item.Cells.Count; i++)
{
e.Item.Cells[i].Width = Unit.Pixel(50);
e.Item.Cells[i].Wrap = false;
}
}
}
您可能感興趣的文章:
  • datalist,Repeater和Gridview的區別分析
  • asp.net中讓Repeater和GridView支持DataPager分頁
  • repeater、gridview 在綁定時判斷判斷顯示不同的行樣式或文本
  • ASP.NET MVC4之js css文件合并功能(3)
  • Asp.net程序優化js、css實現合并與壓縮的方法
  • Asp.net_Table控件の單元格縱向合并示例
  • ASP.NET GridView 實現課程表顯示(動態合并單元格)實現步驟
  • asp.net中rdlc 合并行的方法
  • asp.net 合并GridView中某列相同信息的行(單元格)
  • ASP.NET中GridView和Repeater重復數據如何合并

標簽:呼倫貝爾 克拉瑪依 運城 潛江 洛陽 綏化 西藏 阿里

巨人網絡通訊聲明:本文標題《asp.net中GridView和DataGrid相同列合并實現代碼》,本文關鍵詞  asp.net,中,GridView,和,DataGrid,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net中GridView和DataGrid相同列合并實現代碼》相關的同類信息!
  • 本頁收集關于asp.net中GridView和DataGrid相同列合并實現代碼的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 隆回县| 上杭县| 四川省| 蓝山县| 古丈县| 临洮县| 安丘市| 铜陵市| 宜丰县| 商都县| 舟曲县| 雅安市| 新绛县| 绥宁县| 南投市| 理塘县| 湖口县| 威远县| 土默特左旗| 嘉义市| 遂平县| 旬邑县| 绍兴县| 获嘉县| 青神县| 华亭县| 黔西县| 阿克陶县| 荔浦县| 光泽县| 景宁| 四平市| 华蓥市| 仙游县| 夏河县| 磴口县| 新源县| 威信县| 襄垣县| 遵化市| 周宁县|