0

DataList を動的な値 (つまり、特定の場所からの Google API からの距離) にバインドしています。

つまり、x の場所から:

10km先 15km先 など

ここに画像の説明を入力

ItemDataBoundでこのコードを使用する:

private void bindDataList(string location)
{
  DataSet dstProperty = Tbl_PropertyMaster.getPropertiesByLocation(location);
  dlstNearbyProperties.DataSource = dstProperty;
  dlstNearbyProperties.DataBind();
}

.

protected void dlstNearbyProperties_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item ||
         e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Label lblPropId = (Label)e.Item.FindControl("lblPropId");
        Label lblKmAway = (Label)e.Item.FindControl("lblKmAway");
        Label lblPrice = (Label)e.Item.FindControl("lblPrice");
        DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(Convert.ToInt32(lblPropId.Text));
        if (dstEnabledStat.Tables[0].Rows.Count > 0)
        {
            //string origin = "8.5572357 ,76.87649310000006";
            string origin = InitialOrigin;
            string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
            lblKmAway.Text = devTools.getDistance(origin, destination) + " Away";
        }
        lblPrice.Text = getMinnimumOfRoomPrice(Convert.ToInt32(lblPropId.Text));
   }
}

これらの値を昇順または降順でソートする方法はありますか?

注意: 距離は DB 値ではなく、動的です。

これを Button1_Click でソートできますか?

4

1 に答える 1

0

コードで何時間も遊んだ後、私はそれをやった。

以下は GRIDVIEW の場合です。DataList についても同様の手順を実行できます。

ページの読み込み:既存のデータテーブルに追加の列「マイル」を追加しました

protected void Page_Load(object sender, EventArgs e)
{
    dtbl = Tbl_PropertyMaster.SelectAllPropertyAndUserDetails().Tables[0];
    dtbl.Columns.Add("Miles", typeof(int));
    //userId = devTools.checkAdminLoginStatus();
    if (!IsPostBack)
    {
        fillDlPhotoViewAll();
        FillGrProperty();

    }
}

行データ境界:

protected void grProperty_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

    DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(PropId);
    if (dstEnabledStat.Tables[0].Rows.Count > 0)
    {
        string origin = InitialOrigin;
            string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
            decimal Kilometre=0.00M;
            if(devTools.getDistance(origin, destination)!=0)
            {
            Kilometre=Convert.ToDecimal(devTools.getDistance(origin, destination))/1000;
            }
            lblmiles.Text = Kilometre.ToString() + "Kms";
            dtbl.Rows[inn]["Miles"] = Convert.ToInt32(devTools.getDistance(origin, destination));
            inn = inn + 1;
    }
}
ViewState["dtbl"] = dtbl;
}

距離で並べ替え Button_Click:

protected void btnSort_Click(object sender, EventArgs e)
{
    DataTable dataTable;
    dataTable = (DataTable)ViewState["dtbl"];
    if (dataTable.Rows.Count > 0)
    {
        dataTable.DefaultView.Sort = "Miles DESC";
        dataTable.AcceptChanges();
        grProperty.DataSource = dataTable;
        grProperty.DataBind();
    }
}
于 2012-08-27T12:10:27.130 に答える