无法在gridview中找到值 [英] cant find value in gridview

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

问题描述

从下拉列表中获取值并显示在gridview.with此代码当我按下按钮时没有任何事情发生且没有错误来。请帮我解决这个问题

taking the value from dropdownlist and showing in gridview.with this code when i press button nothing happen and no error come.please help me out with that

string a = DropDownList1.SelectedValue.ToString();
SqlConnection con = new SqlConnection(connstring);
string query="SELECT * FROM ['ISB VAS Nodes$'] WHERE Model='"+DropDownList1.Text+"'";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();

推荐答案

'] WHERE Model =' + DropDownList1.Text + < span class =code-string> ';
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
'] WHERE Model='"+DropDownList1.Text+"'"; SqlDataAdapter da = new SqlDataAdapter(query, con); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind();






唯一可能的方法是检查数据表行数

Hi,

Only Possible way is check Data table row count
string a = DropDownList1.SelectedValue.ToString();
SqlConnection con = new SqlConnection(connstring);
string query="SELECT * FROM [''ISB VAS Nodes


''] WHERE Model =''+ DropDownList1.Text +'';
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataTable dt = new DataTable();

da.Fill(dt);

if(dt。 rows.Count> 0)
{
GridView1.DataSourc e = dt;
GridView1.DataBind();
}
其他
{
lblResult.Text =未找到记录;
}
''] WHERE Model=''"+DropDownList1.Text+"''"; SqlDataAdapter da = new SqlDataAdapter(query, con); DataTable dt = new DataTable(); da.Fill(dt); if(dt.rows.Count>0) { GridView1.DataSource = dt; GridView1.DataBind(); } else { lblResult.Text = "No Records Found"; }



你可以将以下代码添加到gridview设计中以显示空消息


And You may Add below code to gridview design for display Empty message

<emptydatatemplate>
No Records Found
</emptydatatemplate>





执行此操作时,如果您收到此消息 - 表示数据库表不包含记录,则与您的匹配查询



谢谢



Siva Rm K



When execute this, If you Got this message - that Means DB Table does not Contain Records, that match to your query

Thanks

Siva Rm K


这篇关于无法在gridview中找到值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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