2013-04-09 52 views
0

我是桌面應用程序開發的新手。將數據集的特定列數綁定到Gridview

我具有包含以下字段的數據集:

BillNo | Descirption | HSN Code | Qty | Rate 

和我有類型數據網格視圖文本框柱的網格圖,其中指定下列。

Sr No. | Descirption  | HSN Code | Qty | Rate | Amount 

我要綁定「描述」,「HSN代碼」,「數量」 &「費率」從數據集中的網格視圖和我想要生成的「SR號」 &以編程方式顯示網格視圖的「金額」。

我該怎麼做?

請幫忙。

回答

1

在運行時創建新的DataTable對象和填充數據表按規定並將其綁定到數據網格或gridview的

如下圖所示:

Private DataTable GetTable() 
    { 

    DataTable table = new DataTable(); 
    table.Columns.Add("Sr No.", typeof(int)); 
    table.Columns.Add("Descirption", typeof(string)); 
    table.Columns.Add("Code", typeof(string)); 
    ......... 
    ........ 


    retrive the data from datasourec in datatable dt 

    //Here first loop through your orignal datatable or dataset 

    forecch(DataRow drow in dt.Rows) 
    { 
     table.Rows.Add("your sr no", drow["Descirption" ],drow["Code"]);  
    } 
    return table; 
    } 
+0

我應該列的名稱相同網格視圖? ie'table.Columns.Add(「Sr No.」,typeof(int));'在網格視圖中,列名是'clmSr',標題文本是'Sr.' @raj – 2013-04-09 10:46:08

+0

謝謝它的完美工作。 ..但仍然有一個問題是,它將列附加到現有的網格視圖列。數據不顯示在現有的列做什麼。 @raj – 2013-04-09 10:54:57

+0

是的,使網格視圖的列名稱相同,它將起作用。 – Gajendra 2013-04-09 11:01:16