hi friends,
i write again my previous question because still i am not getting answer. please give a sample code for when i select checkbox in datagrid, that row cell(1) value is displayed in textbox(this textbox is outside of the datagrid).
and uncheck the checkbox that row cell(1) value removed from textbox. please give a sample javascript code.
Thanks
Loading
Raghavendra UPosted Jul 17, 2010, 3:59 AM
Abhishek KumarPosted Sep 17, 2015, 1:55 AM
ajay rajuPosted Jul 17, 2010, 7:24 AM
This is my sample code:
Javascript:
function ShowMobileNO(Recipient) {
var dataGrid = document.getElementById("<% =dg_contacts.ClientID %>")
var MobileNO = dataGrid.rows[Recipient.value].cells[1].innerHTML;
if (document.getElementById("chkSelect_popup").checked = true) {
document.getElementById("<% =txt_Recipients.ClientID %>").value = document.getElementById("<% =txt_Recipients.ClientID %>").value + MobileNO + "," ;
}
if (document.getElementById("chkSelect_popup").checked = false) {
document.getElementById("<% =txt_Recipients.ClientID %>").value = document.getElementById("<% =txt_Recipients.ClientID %>").value - MobileNO + ",";
}
}
This is my sample code Raghavendra please give Quick Reply.
Raghavendra UPosted Jul 17, 2010, 7:10 AM
ajay rajuPosted Jul 17, 2010, 6:49 AM
its working fine.
but if i checked first checkbox it is not selected but value is taken. please give a solution
Thanks.
Raghavendra UPosted Jul 17, 2010, 6:36 AM
ajay rajuPosted Jul 17, 2010, 5:53 AM
Thanks for you reply. your code is working in Gridview. but i am using Datagrid. my problem is in place of value='<%# Container.DataItemIndex+1 %>' this property, which property i use for Datagrid. because DataGrid doesnot support
for Container.DataItemIndex.
Thanks.
mihir soniPosted Jul 17, 2010, 2:56 AM
Please follow the step and still if you have any problem just let me know... I have written sample code if you cannot understand inform me.
I have taken dummy database which contain only one column called name and i have bound it with gridview after that i add one templet filed which add checkbox to your gridview and in c# code you can add javascript function as in i have show u in c# page.
Here is my aspx page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Here is my c# page.
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string str = e.Row.Cells[0].Text;
CheckBox ch = (CheckBox)e.Row.FindControl("test");
ch.Attributes.Add("onClick", "testing('"+str+"')");
}
}
}