具有多个绑定方法的gridview [英] gridview having more than one bind method

查看:62
本文介绍了具有多个绑定方法的gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做location-city-state-country页面.在location页面中,我有3个下拉列表,并且基于在下拉列表中选择的值将数据绑定到gridview.为此,我使用了以下方法

i am doing location-city-state-country page.in location page i have 3 dropdowns and based on the values selected in dropdown list data to the gridview is binded.for that i use follwing method

public void fillgrid()
       {
           Int32 country_id = Convert.ToInt32(ddcountry.SelectedValue == "" ? "0" : ddcountry.SelectedValue);
           Int32 state_id = Convert.ToInt32(ddstate.SelectedValue == "" ? "0" : ddstate.SelectedValue);
           Int32 city_id = Convert.ToInt32(ddcity.SelectedValue == "" ? "0" : ddcity.SelectedValue);
           Common obj = new Common();
           DataSet ds = obj.BindingGridview(country_id, state_id, city_id);
           gvlocation.DataSource = ds;
           gvlocation.DataBind();
       }


我也有一个搜索按钮,并根据搜索文本框中的值绑定了gridview.为此,我使用了以下代码


i have also a search button and i bind the gridview based on value in search textbox.for that i use follwing code

public void BindGV(string locationname)
     {

         Common obj = new Common();
         locationname = "%" + locationname + "%";
         DataSet ds = obj.GetAllLocation(locationname);
         gvlocation.DataSource = ds.Tables[0];
         gvlocation.DataBind();

     }


问题是在编辑/更新/删除期间我只能将一种方法绑定到gridview.通常我选择第一种方法.但是当我按显示搜索结果的gridview的编辑按钮时,这会导致问题.
受保护的void gvlocation_RowEditing(对象发送者,GridViewEditEventArgs e)
{
gvlocation.EditIndex = e.NewEditIndex;
fillgrid();
}


The problem is that i can bind only one method to gridview during edit/update/delete.normally i select first method.but when i press edit button of gridview which shows search Result, it causes problem .
protected void gvlocation_RowEditing(object sender, GridViewEditEventArgs e)
{
gvlocation.EditIndex = e.NewEditIndex;
fillgrid();
}

推荐答案

更正此行:
Correct this line:
gvlocation.DataSource = ds;




to

gvlocation.DataSource = ds.Tables[0];


您取一个静态标志并设置为搜​​索,然后在u处于编辑模式下时根据标志填充,请记住在下拉列表选择后取消设置
you sd take a static flag and set on search then when u are in edit mode fill according to flag remember to unset after dropdown select


这篇关于具有多个绑定方法的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆