如何在选中该复选框的gridview中获取值. [英] how to get the value in the gridview which the checkbox is checked.

查看:80
本文介绍了如何在选中该复选框的gridview中获取值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在选中该复选框的gridview中获取值
在我的gridview的一列中,当我单击一行中的复选框时,创建了复选框
然后将状态保存到数据库中,并在重新打开站点时保存的状态
显示在gridview中.....



在行命令中,我成功将bit1保存为chek,将bit0保存为未选中的表..但是如何在我的gridview中获取此保存的状态..plzzz告诉我

How do I get the value in the gridview which the checkbox is checked
in my gridview one column I created checkboxs ,when i click that checkbox of a row
then the state is save into database and when reopen the site then the saved state
is show into the gridview.....



in row command i successfully save bit1 for chek and bit0 for uncheck in a table.. but how to get this saved state in my gridview..plzzz tell me

推荐答案

嗨拉希德,

您可以使用网格视图的行命令事件.我已将row命令事件放入您的网格中.您正在使用p_id和u_id.在行命令中获取该ID并将其保存到数据库.在需要时从数据库检索.
Hi Rashid,

You can use Row command event of grid view. I have put the row command event in your grid. you are having p_id and u_id . get that ids at row command and the save it to database. retrieve from database when you want.
<asp:GridView ID="Grid1" runat="server" BackColor="#DEBA84"

        BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"

        CellSpacing="2" Width="90%" Height="10%"

        AutoGenerateColumns="False"

                        AllowPaging="True" AllowSorting="True" PageSize="5"

            onpageindexchanging="Grid1_PageIndexChanging"

            onrowediting="Grid1_RowEditing" onrowupdating="Grid1_RowUpdating" OnRowCommand="Grid1_RowCommand"

            DataKeyNames ="P_id, U_id" >


受保护的void gvCheck_RowDataBound(object sender,GridViewRowEventArgs e)
{
DataTable dt = ViewState ["chk"] as DataTable;

如果(e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk =(CheckBox)e.Row.FindControl("chk");
布尔标志= Convert.ToBoolean(dt.Rows [e.Row.RowIndex] ["Chk"].ToString());//查找表中包含复选框值的列
如果(flag == true)
{
chk.Checked = true;
}

}<
}

我希望这会对您有所帮助
protected void gvCheck_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataTable dt = ViewState["chk"] as DataTable;

if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)e.Row.FindControl("chk");
Boolean flag = Convert.ToBoolean(dt.Rows[e.Row.RowIndex]["Chk"].ToString());// find column of table which contain value for check box
if (flag == true)
{
chk.Checked = true;
}

}<
}

i hope this will help u


拉希德,

您可以在说"复选框的网格中添加一列,现在每个复选框将向用户显示当前行的ID.

现在,当用户检查该复选框时,将触发一个事件,因此,您可以将与该复选框关联的ID存储到某个hiddenfield,或者如果只需要对check事件进行检查,则可以从服务器端进行回发和调用保存状态方法复选框.

而当您加载网格时,只需将选中/取消选中的值显示在复选框中即可.

让我知道您是否有疑问.
Hi Rashid,

You can add a column in grid say checkbox, now each checkbox will have id of the current row shown to user.

Now when user checks that checkbox an event will be fired so at that time you can store id which is associated with the checkbox to some hiddenfield or you can made postback and call save state method from server side if it is just required on check event of checkbox.

and when you load the grid just show the value as per check/uncheck into checkbox.

Let me know if you have a question.


这篇关于如何在选中该复选框的gridview中获取值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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