带复选框的网格视图 [英] Grid view With Check Box

查看:81
本文介绍了带复选框的网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......


在我的项目中...一种情况是我使用带有Checkbox的gridview.将复选框作为模板文件的新列添加到gridview之后..所有回发控件均未执行回发..例如button.i表示没有要求进入服务器...我没有遇到麻烦...请给我建议解决方案..为此


谢谢...,
SriramNidamanuri.

Hi....


In my project...one of the scenario i am using gridview with Checkbox .After adding the checkbox to the gridview as a new column of template filed..no postback was performed by all postback controls..like button.i mean no requst goes to server...i did not get wat happened ...plzz suggest me the solution..for this.


Thanks...,
SriramNidamanuri.

推荐答案


试试这个
Hi ,
Try this
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        if (((CheckBox)GridView1.Rows[e.RowIndex].FindControl("CheckBox1")) is CheckBox)
        {
            using (
                SqlConnection con =
                    new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("UPDATE dbo.cate  SET cate = @cate , chk = @chk  where id  = @id", con);
                cmd.Parameters.AddWithValue("@cate",
                                            ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text);
 
                cmd.Parameters.AddWithValue("@chk",
                                            ((CheckBox)GridView1.Rows[e.RowIndex].FindControl("CheckBox1")).Checked);
 
                cmd.Parameters.AddWithValue("@id",
                                            ((Label)GridView1.Rows[e.RowIndex].FindControl("Label1")).Text);
 
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
 
                GridView1.EditIndex = -1;
                bind();
            }
        }



最好的问候
M.Mitwalli



Best Regards
M.Mitwalli


请参考以下主题,有关CP的一些好文章:
在GridView控件中选择多个复选框 [ ^ ]
带有文本框,复选框,单选按钮和下拉列表的可编辑Gridview [ ^ ]

这里还有一些其他网站,它们将为您做一些必要的事情:
在ASP.NET GridView控件中使用复选框 [带有CheckBox的GridView –全选并突出显示所选行 [检查GridView中的所有复选框 [ ^ ]
Please refer following threads, some of good articles on CP:
Selecting multiple checkboxes inside a GridView control[^]
Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List[^]

Here are some other websites too, which will do some needful for you:
Using Checkbox in ASP.NET GridView Control[^]
GridView with CheckBox – Select All and Highlight Selected Row[^]
Checking all CheckBoxes in a GridView[^]


这篇关于带复选框的网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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