![](/img/trans.png)
[英]checkboxed selected rows from gridview1 to gridview2 ASP.NET C#
[英]How to programatically select the data from GridView1's first row 4th column cell on page load and save it to a variable in C# asp.net
我是asp.net和C#Web應用程序開發的新手。
我的問題是:我有一個GridView1
綁定到從SQL Server表獲取數據的數據源。
Gridview1
有以下列:
此數據也會按下拉列表日期進行過濾和排序
我想要做的是當我的頁面加載緯度和經度列的第一行值被賦值給我的變量lat和lng
這就是我寫的,基本上lat和lng變量將在我的另一個函數中使用:
Double lat, lng;
lat = Convert.ToDouble(GridView1.Rows[1].Cells[4].Text);
lng = Convert.ToDouble(GridView1.Rows[1].Cells[5].Text);
GLatLng latlong = new GLatLng(lat, lng);
GMap1.setCenter(latlong, 10);
拋出以下異常:
指數超出范圍。 必須是非負數且小於集合的大小。
gridview數據永遠不會為null,它總是有一些數據
在訪問行集合Gridview.Datasource = yourdatasource Gridview.bind()之前,請確保將gridview綁定到數據源。
嘗試這個
lat = Convert.ToDouble(GridView1.Rows[0].Cells[3].Text);
因為Gridview Rows
和Cells
始終從0 (零)開始。
要么
最好的辦法是用.findControl()方法的Controls
像下面。
string lat = ((Label)GridView1.Rows[0].FindControl("labelID")).Text
但是,對於上面的代碼,您必須在GridView
中的<ItemTemplate>
中使用<asp:label>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.