Private Function SelectedValues() As String
Dim strValues As String = ""
For i As Integer = 0 To GridView.Rows.Count - 1
Dim chkSelect As CheckBox
chkSelect = CType(gvClientContact.Rows(i).FindControl("chkSelect"), CheckBox)
If Not chkSelect Is Nothing Then
If chkSelect.Checked Then
strValues &= CStr(GridView.DataKeys(i).Values(0)) & ","
End If
End If10/09/2010
Next
Return strValues.Trim(CChar(","))
End Function
Showing posts with label grid view. Show all posts
Showing posts with label grid view. Show all posts
Friday, October 28, 2011
Get selected values of checkbox from GridView in ASP.NET
Friday, October 14, 2011
Get selected checkbox value of ASP.NET GRID VIEW using JavaScript
<script language="javascript" type="text/javascript">
function GetSelected(objchk, HId) {
var hdnIds = document.getElementById("<%= hdnIds.ClientId %>");
if (hdnIds.value.length == 0) {
hdnIds.value = ",";
}
if (objchk.checked == true) {
hdnIds.value = hdnIds.value + HId + ",";
}
else {
hdnIds.value = hdnIds.value.replace("," + HId + ",", ",")
}
}
</script>
'Bind this function like On GridView's RowDataBound Event.
Private Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
Dim chkSelect As CheckBox = CType(e.Row.FindControl("chkSelect"), CheckBox)
If Not chkSelect Is Nothing Then
chkSelect.Attributes.Add("onclick", "GetSelected(this,'" & DataBinder.Eval(e.Row.DataItem, "HId").ToString() & "');")
End If
End Sub
'Now you have comma seperated values of HIds in hdnIds hidden field which you can use accordingly
Labels:
Asp.Net,
checkbox,
grid view,
Javascript,
selected value
Subscribe to:
Posts (Atom)