我想过滤datarowview .....如果我没有sqldatasource中的下拉值 [英] I want to filter datarowview .....in case I dont have that dropdown value in sqldatasource

查看:38
本文介绍了我想过滤datarowview .....如果我没有sqldatasource中的下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过从下拉列表中选择值来在gridView中输入短列表...当我在dropDown中有vsalue而不是在gridview中时出现问题而不是它给我错误

I want short list rows in gridView by selecting values from dropdown list...problem arises when i have a vsalue in dropDown but not in gridview than it Give me error "

index 0 is either negative or above rows count







我尝试过:




"

What I have tried:

protected void ddlAllEngineerSolver_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataView productsTable = (DataView)
               SqlDataSourceAssignedComplains.Select(DataSourceSelectArguments.Empty);
        productsTable.RowFilter = string.Format("EngName = '{0}'",
            ddlAllEngineerSolver.SelectedItem);
        DataRowView row1 = null;
        if ((row1 = (DataRowView)productsTable[0]).ToString()!="0")
        {
             DataTable dataTable = row1.DataView.ToTable();
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
        }
      
    }

推荐答案

在使用productsTable [0]之前检查是否有行产品表。



Before using productsTable[0] check if there are rows in product table.

if (productsTable != null && productsTable.Rows.Count > 0 && (row1 = (DataRowView)productsTable[0]).ToString()!="0")


我同意检查行计数可以防止你遇到的问题获得。您实际上可以将代码重写为:



I would agree that checking the Row Count can prevent the issue you are getting. You could actually rewrite your code to this:

protected void ddlAllEngineerSolver_SelectedIndexChanged(object sender, EventArgs e){
        DataView productsTable = (DataView)
        SqlDataSourceAssignedComplains.Select(DataSourceSelectArguments.Empty);
        productsTable.RowFilter = string.Format("EngName = '{0}'",
            ddlAllEngineerSolver.SelectedItem);

 	    DataTable dtResult = productsTable.ToTable();
        if (dtResult.Rows.Count > 0)
        {
            GridView1.DataSource = dtResult
            GridView1.DataBind();
        }
	    else{
		         //display no result found
	    }   
}


这篇关于我想过滤datarowview .....如果我没有sqldatasource中的下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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