473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Gridview access from Javascript

I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.

1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.

2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.

Thanks.
Nov 28 '07 #1
4 8342
On 28 ìÉÓ, 06:59, marksommervi...@yahoo.com wrote:
I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.

1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.

2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.

Thanks.
Regarding for your first question: you can attach client-side script
within RowDataBound event handler:

<asp:GridView id="GridView1"
OnRowDataBound="GridView1_RowDataBound" ...
<Columns>
<asp:templateField>
<itemtemplate><sp:CheckBox id="CheckBox1" runat="server"></
itemtemplate>
</asp:templateField>

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox CheckBox1 = (CheckBox)e.Row.FindControl("CheckBox1");
CheckBox1.Attributes["onclick"] = string.Format("alert({0});",
e.Row.RowIndex);
}
}

Regards,
Mykola
http://marss.co.ua
Nov 28 '07 #2
ma*************@yahoo.com wrote:
I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.

1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.

2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.

Thanks.

This is for your 2nd?

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.Pager Then
CType(e.Row.FindControl("Button1"), Button).Enabled = False
End If
End Sub

Jayakrishnan
Nov 28 '07 #3
On Nov 27, 10:20 pm, marss <marss...@gmail.comwrote:
On 28 ìÉÓ, 06:59, marksommervi...@yahoo.com wrote:
I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.
1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.
2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.
Thanks.

Regarding for your first question: you can attach client-side script
within RowDataBound event handler:

<asp:GridView id="GridView1"
OnRowDataBound="GridView1_RowDataBound" ...
<Columns>
<asp:templateField>
<itemtemplate><sp:CheckBox id="CheckBox1" runat="server"></
itemtemplate>
</asp:templateField>

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox CheckBox1 = (CheckBox)e.Row.FindControl("CheckBox1");
CheckBox1.Attributes["onclick"] = string.Format("alert({0});",
e.Row.RowIndex);
}

}

Regards,
Mykolahttp://marss.co.ua
Thanks Mykola, I'll give it a shot.
Nov 28 '07 #4
On Nov 27, 11:01 pm, Jayakrishnan <jayakrish...@iinterchange.com>
wrote:
marksommervi...@yahoo.com wrote:
I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.
1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.
2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.
Thanks.

This is for your 2nd?

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.Pager Then
CType(e.Row.FindControl("Button1"), Button).Enabled = False
End If
End Sub

Jayakrishnan

Thanks but I need to be able to access Button1 from Javascript. The
idea is that if no check boxes are checked then Button1 should be
disabled. My javascript function for the checkbox click will check to
see if all are unchecked then disable the button.
Nov 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Machi | last post by:
let say i have a web form with a button on it ... when i click the button, it will pop up one small window to allow me to save a pdf file, everything is done using code behind as below ... however,...
3
by: McGeeky | last post by:
Hi. Is it possible to iterate through the items in a GridView using JavaScript on the client? -- McGeeky http://mcgeeky.blogspot.com
1
by: akjal | last post by:
Hi all, I have one user control with 2 gridview and 2 tabs(created using javascript).When tab1 clicks Gridview1 will b shown(this is the default) and tab2 click shows Gridview2. These 2 gridviews...
3
by: mrbadboy | last post by:
Hi, I need to access javascript value from flash or i need to access html controls value(like hidden or text box value) from flash. How can i get i from flash. Can you help me how to get it ? ...
0
by: nospam | last post by:
Hello, I need a column in a GridView to trigger a javascript function ( to play an MP3 file). I am catching the RowCreated event from the GridView. I then add my javascript code like this: ...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
0
by: baburmm | last post by:
Hai, I want to get the footer textbox value in gridview using javascript any one help me Regards, Babu.K
0
by: baburmm | last post by:
hello friends i want to get the footer row textbox value of the gridview using javascript for validating it. how can i get it is there any coding pls help me Thanks in advance, Regards. Babu.K
1
by: baburmm | last post by:
hello friends i want to get the footer row textbox value of the gridview using javascript for validating it. how can i get it is there any coding pls help me Thanks in advance, Regards. Babu.K
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.