如何访问选中的行值 [英] How to access checked row values

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

问题描述

我想在选中复选框时将''amt''列的值添加到变量''v_amt''中。在同一个变量中,我希望在取消选中复选框时减去该值。



这是当前的代码,但我无法将要求纳入其中。

 CheckBox chkTest =(CheckBox)sender; 
GridViewRow grdRow =(GridViewRow)chkTest.NamingContainer;
TextBox txtname =(TextBox)grdRow.FindControl( txtName);
TextBox txtlocation =(TextBox)grdRow.FindControl( txtLocation);
if (chkTest.Checked)
{
txtname.ReadOnly = false ;
txtlocation.ReadOnly = false ;
txtname.ForeColor = System.Drawing.Color.Black;
txtlocation.ForeColor = System.Drawing.Color.Black;

}
else
{
txtname.ReadOnly = ;
txtlocation.ReadOnly = true ;
txtname.ForeColor = System.Drawing.Color.Blue;
txtlocation.ForeColor = System.Drawing.Color.Blue;
}





有人可以指导我。

解决方案

将gridview的DataKeyNames属性添加到列表中,并通过以下代码检索特定行的以下值....





  int  index =  int  .Parse(e.CommandArgument.ToString ()); 
string value = grdView.DataKeys [index] .Value.ToString()。Trim( );


 受保护的  Sub  chkAuth_CheckedChanged( ByVal  sender  As  对象 ByVal  e  As  EventArgs)
Dim chk As CheckBox
chk = sender
如果 chk.Checked = True 那么
Dim gr 作为 GridViewRow
gr = CTYPE (chk.Parent.Parent ,GridViewRow)
grdSample.Rows(gr.RowIndex).Cells( 4 )。文本= i + 1
grdSample.Rows(gr.RowIndex).Cells( 5 )。text =
否则
Dim gr 作为 GridViewRow
gr = CType (chk.Parent。 Parent,GridViewRow)
grdSample.Rows(gr.RowIndex).Cells( 4 )。Text =
grdSample.Rows(gr.RowIndex).Cells( 5 )。 Text =
结束 如果
结束 Sub



 


I want to add the values of ''amt'' column into a variable ''v_amt'' when checkbox selected. In the same variable I want to minus the value when I deselect the checkbox.

Here is the prevailing code but I could not make the requirement into it.

CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
TextBox txtname = (TextBox)grdRow.FindControl("txtName");
TextBox txtlocation = (TextBox)grdRow.FindControl("txtLocation");
if (chkTest.Checked)
{
    txtname.ReadOnly = false;
    txtlocation.ReadOnly = false;
    txtname.ForeColor = System.Drawing.Color.Black;
    txtlocation.ForeColor = System.Drawing.Color.Black;

}
else
{
    txtname.ReadOnly = true;
    txtlocation.ReadOnly = true;
    txtname.ForeColor = System.Drawing.Color.Blue;
    txtlocation.ForeColor = System.Drawing.Color.Blue;
}



Can some one guide me.

解决方案

Add DataKeyNames property of gridview to the list and the following value of the particular row can be retrieved by the following code....


int index = int.Parse(e.CommandArgument.ToString());
string value = grdView.DataKeys[index].Value.ToString().Trim();


Protected Sub chkAuth_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
       Dim chk As New CheckBox
       chk = sender
       If chk.Checked = True Then
           Dim gr As GridViewRow
           gr = CType(chk.Parent.Parent, GridViewRow)
           grdSample.Rows(gr.RowIndex).Cells(4).Text = i + 1
           grdSample.Rows(gr.RowIndex).Cells(5).Text = "Yes"
       Else
           Dim gr As GridViewRow
           gr = CType(chk.Parent.Parent, GridViewRow)
           grdSample.Rows(gr.RowIndex).Cells(4).Text = ""
           grdSample.Rows(gr.RowIndex).Cells(5).Text = ""
       End If
   End Sub



这篇关于如何访问选中的行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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