更新gridview,其中dropdownlist值已更改,对您有所帮助! [英] Update gridview where dropdownlist value changed help!

查看:50
本文介绍了更新gridview,其中dropdownlist值已更改,对您有所帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码专家,这是什么原因,为什么不起作用,谢谢

here''s my code guys whats missing on this why dont work thanks

protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            dt = con.GetResults("select * from Categories where CategoryName='" + ddlCategories.Text + "'");

            string CategoryID = "";

            for (int x = 0; x < dt.Rows.Count; x++)
            {
                CategoryID = dt.Rows[x]["CategoryID"].ToString();
            }

            DataTable dtFind;

            dtFind = con.GetResults("select ProductName as 'Product Name', Price from Products where CategoryId='" + CategoryID + "'");

            ProductsGridView.DataSource = dtFind;
            ProductsGridView.DataBind();
        }



[edit]已删除呼喊声-OriginalGriff [/edit]



[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

很多!首先开始:

尽管您没有提到无法正常工作"的部分,但根据您的问题标题更新了下拉列表值已更改的gridview
1.这里没有UPDATE查询.只是SELECT查询.

2.您执行一个for循环来定义CategoryID:
Lots! To start with:

Though you have not mentioned ''not working'' part but based on your question title Update gridview where dropdownlist value changed
1. There is no UPDATE query here. Just SELECT query.

2. You do a for loop to define CategoryID:
for (int x = 0; x < dt.Rows.Count; x++)
{
   CategoryID = dt.Rows[x]["CategoryID"].ToString();
}


这没有任何意义.最后,您只是为CategoryID分配了所获取表的最后一行的值.

3.您在邀请SQL注入的查询中直接使用文本值.您应该使用参数化查询.


This does not makes any sense. At the end you are just assigning CategoryID a value of last row from your table fetched.

3. You are using direct usage of text values in queries inviting SQL Injection. You should use parametrized query.


这篇关于更新gridview,其中dropdownlist值已更改,对您有所帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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