By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

DataGrid edited row and jScript

P: n/a
Hi
I wanna to create a jscript function that sets the value of a textbox into a
datagrid, But the problem is How can I obtain the name of the textbox and
send it to my jscript function???? The textbox is in a TemplateColumn

The Idea is sent to the funcion the name of the control and then pass it to
another window and then this child window must set the values of the
control. But for simplicity the problem get reduced to obtain the name of
the textbox

This is the call of my fHelpItm jscript function, like you see I associate
the call to onclick event for the IMG control
==================
<EditItemTemplate>
Codigo<asp:TextBox id="txtCod" runat="server"
Width="87px"></asp:TextBox>
<IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
</EditItemTemplate>
==================

the function simplified function is something like this
=======================
function fHelpItm(Codigo)
{
if confirm(' Do you wanna set a value for ' + Codigo)
document.forms[0].elements[Codigo].value ='Hello world' <<<HERE
is the problem
}
=====================
jscript says that the name of the control "txtCod" is not an object and that
is correct because the name sure is something like "Datagrid__ctl2_txtCod"
so the question is How can I obtain the correct name of the control
THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
bye
Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi!
You cannot get the TextBox using its ID (txtCod), because in datagrid you
have many items (here textboxes) with the same ID. But in one page you cannot
have two controls with the same ID. So, the framework places some prefix to
all the controls. That's why it is like "Datagrid__ctl2_txtCod". If you want
to have the textbox available on the client (in js function) you have to use
the ID with the prefix

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi
I wanna to create a jscript function that sets the value of a textbox into a
datagrid, But the problem is How can I obtain the name of the textbox and
send it to my jscript function???? The textbox is in a TemplateColumn

The Idea is sent to the funcion the name of the control and then pass it to
another window and then this child window must set the values of the
control. But for simplicity the problem get reduced to obtain the name of
the textbox

This is the call of my fHelpItm jscript function, like you see I associate
the call to onclick event for the IMG control
==================
<EditItemTemplate>
Codigo<asp:TextBox id="txtCod" runat="server"
Width="87px"></asp:TextBox>
<IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
</EditItemTemplate>
==================

the function simplified function is something like this
=======================
function fHelpItm(Codigo)
{
if confirm(' Do you wanna set a value for ' + Codigo)
document.forms[0].elements[Codigo].value ='Hello world' <<<HERE
is the problem
}
=====================
jscript says that the name of the control "txtCod" is not an object and that
is correct because the name sure is something like "Datagrid__ctl2_txtCod"
so the question is How can I obtain the correct name of the control
THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
bye

Nov 19 '05 #2

P: n/a
HI Kostadin

I got the idea, but how can i get the "real name" of the control??? how can
I "build" the name ????

onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
^
How I must right this part??---------- |

I guess that is the key right?? how to write the control name in order to
send to my jscript funcion
Thanks
Bye


"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:31**********************************@microsof t.com...
Hi!
You cannot get the TextBox using its ID (txtCod), because in datagrid you
have many items (here textboxes) with the same ID. But in one page you
cannot
have two controls with the same ID. So, the framework places some prefix
to
all the controls. That's why it is like "Datagrid__ctl2_txtCod". If you
want
to have the textbox available on the client (in js function) you have to
use
the ID with the prefix

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi
I wanna to create a jscript function that sets the value of a textbox
into a
datagrid, But the problem is How can I obtain the name of the textbox and
send it to my jscript function???? The textbox is in a TemplateColumn

The Idea is sent to the funcion the name of the control and then pass it
to
another window and then this child window must set the values of the
control. But for simplicity the problem get reduced to obtain the name of
the textbox

This is the call of my fHelpItm jscript function, like you see I
associate
the call to onclick event for the IMG control
==================
<EditItemTemplate>
Codigo<asp:TextBox id="txtCod" runat="server"
Width="87px"></asp:TextBox>
<IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')"
alt=""
src="../Images/iconBuscar.jpg">
</EditItemTemplate>
==================

the function simplified function is something like this
=======================
function fHelpItm(Codigo)
{
if confirm(' Do you wanna set a value for ' + Codigo)
document.forms[0].elements[Codigo].value ='Hello world'
<<<HERE
is the problem
}
=====================
jscript says that the name of the control "txtCod" is not an object and
that
is correct because the name sure is something like
"Datagrid__ctl2_txtCod"
so the question is How can I obtain the correct name of the control
THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
bye

Nov 19 '05 #3

P: n/a
The only thing that appears in my mind is:
1. Handle the ItemDataBound event of the grid
2. Inside the handler construct the ID of the TextBox (Datagrid__ctl2_txtCod)
3. Get your button through e.Item.FindControl("myButton")
4. Add attribute - myButton.Attributes.Add("onclick",
fHelpItm('Datagrid__ctl2_txtCod'));

It's quite complicated, but I can't think of better way to achieve this.
Sorry!
Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
HI Kostadin

I got the idea, but how can i get the "real name" of the control??? how can
I "build" the name ????

onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
^
How I must right this part??---------- |

I guess that is the key right?? how to write the control name in order to
send to my jscript funcion
Thanks
Bye


"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:31**********************************@microsof t.com...
Hi!
You cannot get the TextBox using its ID (txtCod), because in datagrid you
have many items (here textboxes) with the same ID. But in one page you
cannot
have two controls with the same ID. So, the framework places some prefix
to
all the controls. That's why it is like "Datagrid__ctl2_txtCod". If you
want
to have the textbox available on the client (in js function) you have to
use
the ID with the prefix

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi
I wanna to create a jscript function that sets the value of a textbox
into a
datagrid, But the problem is How can I obtain the name of the textbox and
send it to my jscript function???? The textbox is in a TemplateColumn

The Idea is sent to the funcion the name of the control and then pass it
to
another window and then this child window must set the values of the
control. But for simplicity the problem get reduced to obtain the name of
the textbox

This is the call of my fHelpItm jscript function, like you see I
associate
the call to onclick event for the IMG control
==================
<EditItemTemplate>
Codigo<asp:TextBox id="txtCod" runat="server"
Width="87px"></asp:TextBox>
<IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')"
alt=""
src="../Images/iconBuscar.jpg">
</EditItemTemplate>
==================

the function simplified function is something like this
=======================
function fHelpItm(Codigo)
{
if confirm(' Do you wanna set a value for ' + Codigo)
document.forms[0].elements[Codigo].value ='Hello world'
<<<HERE
is the problem
}
=====================
jscript says that the name of the control "txtCod" is not an object and
that
is correct because the name sure is something like
"Datagrid__ctl2_txtCod"
so the question is How can I obtain the correct name of the control
THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
bye


Nov 19 '05 #4

P: n/a
Hi Kostadin

Thanks por the tip, I got only one dub how to do the second point of your
sugestion "construct the ID of the TextBox (Datagrid__ctl2_txtCod)" and one
more thing, I am using "TemplateColumns" so your first point is
aplicable???
"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:42**********************************@microsof t.com...
The only thing that appears in my mind is:
1. Handle the ItemDataBound event of the grid
2. Inside the handler construct the ID of the TextBox
(Datagrid__ctl2_txtCod)
3. Get your button through e.Item.FindControl("myButton")
4. Add attribute - myButton.Attributes.Add("onclick",
fHelpItm('Datagrid__ctl2_txtCod'));

It's quite complicated, but I can't think of better way to achieve this.
Sorry!
Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
HI Kostadin

I got the idea, but how can i get the "real name" of the control??? how
can
I "build" the name ????

onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
^
How I must right this part??---------- |

I guess that is the key right?? how to write the control name in order to
send to my jscript funcion
Thanks
Bye


"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:31**********************************@microsof t.com...
> Hi!
> You cannot get the TextBox using its ID (txtCod), because in datagrid
> you
> have many items (here textboxes) with the same ID. But in one page you
> cannot
> have two controls with the same ID. So, the framework places some
> prefix
> to
> all the controls. That's why it is like "Datagrid__ctl2_txtCod". If you
> want
> to have the textbox available on the client (in js function) you have
> to
> use
> the ID with the prefix
>
> Hope that helps!
> Regards,
> Kostadin Kostov
>
> "SergioT" wrote:
>
>> Hi
>>
>>
>> I wanna to create a jscript function that sets the value of a textbox
>> into a
>> datagrid, But the problem is How can I obtain the name of the textbox
>> and
>> send it to my jscript function???? The textbox is in a TemplateColumn
>>
>> The Idea is sent to the funcion the name of the control and then pass
>> it
>> to
>> another window and then this child window must set the values of the
>> control. But for simplicity the problem get reduced to obtain the name
>> of
>> the textbox
>>
>> This is the call of my fHelpItm jscript function, like you see I
>> associate
>> the call to onclick event for the IMG control
>> ==================
>> <EditItemTemplate>
>> Codigo<asp:TextBox id="txtCod" runat="server"
>> Width="87px"></asp:TextBox>
>> <IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')"
>> alt=""
>> src="../Images/iconBuscar.jpg">
>> </EditItemTemplate>
>> ==================
>>
>> the function simplified function is something like this
>> =======================
>> function fHelpItm(Codigo)
>> {
>> if confirm(' Do you wanna set a value for ' + Codigo)
>> document.forms[0].elements[Codigo].value ='Hello world'
>> <<<HERE
>> is the problem
>> }
>> =====================
>> jscript says that the name of the control "txtCod" is not an object
>> and
>> that
>> is correct because the name sure is something like
>> "Datagrid__ctl2_txtCod"
>> so the question is How can I obtain the correct name of the control
>>
>>
>> THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
>> bye
>>
>>
>>


Nov 19 '05 #5

P: n/a
I mean if the needed ID is Datagrid__ctl2_txtCod -
string id = "Datagrid__ctl" + e.Item.ItemIndex + "_txtCod";

And also - yes, it's applicable. It doesn't matter if you use TemplateColumn
(I almost always use them). The ItemDataBound event doesn't depend on the
column type that you use.

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi Kostadin

Thanks por the tip, I got only one dub how to do the second point of your
sugestion "construct the ID of the TextBox (Datagrid__ctl2_txtCod)" and one
more thing, I am using "TemplateColumns" so your first point is
aplicable???
"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:42**********************************@microsof t.com...
The only thing that appears in my mind is:
1. Handle the ItemDataBound event of the grid
2. Inside the handler construct the ID of the TextBox
(Datagrid__ctl2_txtCod)
3. Get your button through e.Item.FindControl("myButton")
4. Add attribute - myButton.Attributes.Add("onclick",
fHelpItm('Datagrid__ctl2_txtCod'));

It's quite complicated, but I can't think of better way to achieve this.
Sorry!
Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
HI Kostadin

I got the idea, but how can i get the "real name" of the control??? how
can
I "build" the name ????

onclick="javascript:fHelpItm('txtCod')" alt=""
src="../Images/iconBuscar.jpg">
^
How I must right this part??---------- |

I guess that is the key right?? how to write the control name in order to
send to my jscript funcion
Thanks
Bye


"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:31**********************************@microsof t.com...
> Hi!
> You cannot get the TextBox using its ID (txtCod), because in datagrid
> you
> have many items (here textboxes) with the same ID. But in one page you
> cannot
> have two controls with the same ID. So, the framework places some
> prefix
> to
> all the controls. That's why it is like "Datagrid__ctl2_txtCod". If you
> want
> to have the textbox available on the client (in js function) you have
> to
> use
> the ID with the prefix
>
> Hope that helps!
> Regards,
> Kostadin Kostov
>
> "SergioT" wrote:
>
>> Hi
>>
>>
>> I wanna to create a jscript function that sets the value of a textbox
>> into a
>> datagrid, But the problem is How can I obtain the name of the textbox
>> and
>> send it to my jscript function???? The textbox is in a TemplateColumn
>>
>> The Idea is sent to the funcion the name of the control and then pass
>> it
>> to
>> another window and then this child window must set the values of the
>> control. But for simplicity the problem get reduced to obtain the name
>> of
>> the textbox
>>
>> This is the call of my fHelpItm jscript function, like you see I
>> associate
>> the call to onclick event for the IMG control
>> ==================
>> <EditItemTemplate>
>> Codigo<asp:TextBox id="txtCod" runat="server"
>> Width="87px"></asp:TextBox>
>> <IMG id="imgBuscar" onclick="javascript:fHelpItm('txtCod')"
>> alt=""
>> src="../Images/iconBuscar.jpg">
>> </EditItemTemplate>
>> ==================
>>
>> the function simplified function is something like this
>> =======================
>> function fHelpItm(Codigo)
>> {
>> if confirm(' Do you wanna set a value for ' + Codigo)
>> document.forms[0].elements[Codigo].value ='Hello world'
>> <<<HERE
>> is the problem
>> }
>> =====================
>> jscript says that the name of the control "txtCod" is not an object
>> and
>> that
>> is correct because the name sure is something like
>> "Datagrid__ctl2_txtCod"
>> so the question is How can I obtain the correct name of the control
>>
>>
>> THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
>> bye
>>
>>
>>


Nov 19 '05 #6

P: n/a
HELLO Kostadin

I DID IT!!!!!!!

Thanks a lot, your Idea was the the way!!! I put my code if you wanna take
a look THANKS again

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim img As New WebControls.Image()
img = e.Item.FindControl("imgBuscar")
If Not img Is Nothing Then
Dim c As Control
Dim s As String
For Each c In e.Item.Cells(1).Controls
If TypeOf c Is TextBox Then
s = c.ClientID
End If
Next
If s.Trim.Length > 0 Then
img.Attributes.Add("onclick", "fHelpItm('" & s & "', 'txtNomItem',
true);")
End If
End If
End Sub
Bye

"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:5D**********************************@microsof t.com...
I mean if the needed ID is Datagrid__ctl2_txtCod -
string id = "Datagrid__ctl" + e.Item.ItemIndex + "_txtCod";

And also - yes, it's applicable. It doesn't matter if you use
TemplateColumn
(I almost always use them). The ItemDataBound event doesn't depend on the
column type that you use.

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi Kostadin

Thanks por the tip, I got only one dub how to do the second point of your
sugestion "construct the ID of the TextBox (Datagrid__ctl2_txtCod)" and
one
more thing, I am using "TemplateColumns" so your first point is
aplicable???
"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:42**********************************@microsof t.com...
> The only thing that appears in my mind is:
> 1. Handle the ItemDataBound event of the grid
> 2. Inside the handler construct the ID of the TextBox
> (Datagrid__ctl2_txtCod)
> 3. Get your button through e.Item.FindControl("myButton")
> 4. Add attribute - myButton.Attributes.Add("onclick",
> fHelpItm('Datagrid__ctl2_txtCod'));
>
> It's quite complicated, but I can't think of better way to achieve
> this.
> Sorry!
> Hope that helps!
> Regards,
> Kostadin Kostov
>
> "SergioT" wrote:
>
>> HI Kostadin
>>
>> I got the idea, but how can i get the "real name" of the control???
>> how
>> can
>> I "build" the name ????
>>
>> onclick="javascript:fHelpItm('txtCod')" alt=""
>> src="../Images/iconBuscar.jpg">
>> ^
>> How I must right this part??---------- |
>>
>> I guess that is the key right?? how to write the control name in order
>> to
>> send to my jscript funcion
>>
>>
>> Thanks
>> Bye
>>
>>
>>
>>
>> "Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
>> message news:31**********************************@microsof t.com...
>> > Hi!
>> > You cannot get the TextBox using its ID (txtCod), because in
>> > datagrid
>> > you
>> > have many items (here textboxes) with the same ID. But in one page
>> > you
>> > cannot
>> > have two controls with the same ID. So, the framework places some
>> > prefix
>> > to
>> > all the controls. That's why it is like "Datagrid__ctl2_txtCod". If
>> > you
>> > want
>> > to have the textbox available on the client (in js function) you
>> > have
>> > to
>> > use
>> > the ID with the prefix
>> >
>> > Hope that helps!
>> > Regards,
>> > Kostadin Kostov
>> >
>> > "SergioT" wrote:
>> >
>> >> Hi
>> >>
>> >>
>> >> I wanna to create a jscript function that sets the value of a
>> >> textbox
>> >> into a
>> >> datagrid, But the problem is How can I obtain the name of the
>> >> textbox
>> >> and
>> >> send it to my jscript function???? The textbox is in a
>> >> TemplateColumn
>> >>
>> >> The Idea is sent to the funcion the name of the control and then
>> >> pass
>> >> it
>> >> to
>> >> another window and then this child window must set the values of
>> >> the
>> >> control. But for simplicity the problem get reduced to obtain the
>> >> name
>> >> of
>> >> the textbox
>> >>
>> >> This is the call of my fHelpItm jscript function, like you see I
>> >> associate
>> >> the call to onclick event for the IMG control
>> >> ==================
>> >> <EditItemTemplate>
>> >> Codigo<asp:TextBox id="txtCod" runat="server"
>> >> Width="87px"></asp:TextBox>
>> >> <IMG id="imgBuscar"
>> >> onclick="javascript:fHelpItm('txtCod')"
>> >> alt=""
>> >> src="../Images/iconBuscar.jpg">
>> >> </EditItemTemplate>
>> >> ==================
>> >>
>> >> the function simplified function is something like this
>> >> =======================
>> >> function fHelpItm(Codigo)
>> >> {
>> >> if confirm(' Do you wanna set a value for ' + Codigo)
>> >> document.forms[0].elements[Codigo].value ='Hello world'
>> >> <<<HERE
>> >> is the problem
>> >> }
>> >> =====================
>> >> jscript says that the name of the control "txtCod" is not an object
>> >> and
>> >> that
>> >> is correct because the name sure is something like
>> >> "Datagrid__ctl2_txtCod"
>> >> so the question is How can I obtain the correct name of the control
>> >>
>> >>
>> >> THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
>> >> bye
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #7

P: n/a
I'm glad to help!
Just one recommendation... instead of this code:
For Each c In e.Item.Cells(1).Controls
If TypeOf c Is TextBox Then
s = c.ClientID
End If
Next

use this:
c = e.Item.FindControl("txtCod");
s = c.ClientID

Regards,
Kostadin Kostov

"SergioT" wrote:
HELLO Kostadin

I DID IT!!!!!!!

Thanks a lot, your Idea was the the way!!! I put my code if you wanna take
a look THANKS again

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim img As New WebControls.Image()
img = e.Item.FindControl("imgBuscar")
If Not img Is Nothing Then
Dim c As Control
Dim s As String
For Each c In e.Item.Cells(1).Controls
If TypeOf c Is TextBox Then
s = c.ClientID
End If
Next
If s.Trim.Length > 0 Then
img.Attributes.Add("onclick", "fHelpItm('" & s & "', 'txtNomItem',
true);")
End If
End If
End Sub
Bye

"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:5D**********************************@microsof t.com...
I mean if the needed ID is Datagrid__ctl2_txtCod -
string id = "Datagrid__ctl" + e.Item.ItemIndex + "_txtCod";

And also - yes, it's applicable. It doesn't matter if you use
TemplateColumn
(I almost always use them). The ItemDataBound event doesn't depend on the
column type that you use.

Hope that helps!
Regards,
Kostadin Kostov

"SergioT" wrote:
Hi Kostadin

Thanks por the tip, I got only one dub how to do the second point of your
sugestion "construct the ID of the TextBox (Datagrid__ctl2_txtCod)" and
one
more thing, I am using "TemplateColumns" so your first point is
aplicable???
"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:42**********************************@microsof t.com...
> The only thing that appears in my mind is:
> 1. Handle the ItemDataBound event of the grid
> 2. Inside the handler construct the ID of the TextBox
> (Datagrid__ctl2_txtCod)
> 3. Get your button through e.Item.FindControl("myButton")
> 4. Add attribute - myButton.Attributes.Add("onclick",
> fHelpItm('Datagrid__ctl2_txtCod'));
>
> It's quite complicated, but I can't think of better way to achieve
> this.
> Sorry!
> Hope that helps!
> Regards,
> Kostadin Kostov
>
> "SergioT" wrote:
>
>> HI Kostadin
>>
>> I got the idea, but how can i get the "real name" of the control???
>> how
>> can
>> I "build" the name ????
>>
>> onclick="javascript:fHelpItm('txtCod')" alt=""
>> src="../Images/iconBuscar.jpg">
>> ^
>> How I must right this part??---------- |
>>
>> I guess that is the key right?? how to write the control name in order
>> to
>> send to my jscript funcion
>>
>>
>> Thanks
>> Bye
>>
>>
>>
>>
>> "Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
>> message news:31**********************************@microsof t.com...
>> > Hi!
>> > You cannot get the TextBox using its ID (txtCod), because in
>> > datagrid
>> > you
>> > have many items (here textboxes) with the same ID. But in one page
>> > you
>> > cannot
>> > have two controls with the same ID. So, the framework places some
>> > prefix
>> > to
>> > all the controls. That's why it is like "Datagrid__ctl2_txtCod". If
>> > you
>> > want
>> > to have the textbox available on the client (in js function) you
>> > have
>> > to
>> > use
>> > the ID with the prefix
>> >
>> > Hope that helps!
>> > Regards,
>> > Kostadin Kostov
>> >
>> > "SergioT" wrote:
>> >
>> >> Hi
>> >>
>> >>
>> >> I wanna to create a jscript function that sets the value of a
>> >> textbox
>> >> into a
>> >> datagrid, But the problem is How can I obtain the name of the
>> >> textbox
>> >> and
>> >> send it to my jscript function???? The textbox is in a
>> >> TemplateColumn
>> >>
>> >> The Idea is sent to the funcion the name of the control and then
>> >> pass
>> >> it
>> >> to
>> >> another window and then this child window must set the values of
>> >> the
>> >> control. But for simplicity the problem get reduced to obtain the
>> >> name
>> >> of
>> >> the textbox
>> >>
>> >> This is the call of my fHelpItm jscript function, like you see I
>> >> associate
>> >> the call to onclick event for the IMG control
>> >> ==================
>> >> <EditItemTemplate>
>> >> Codigo<asp:TextBox id="txtCod" runat="server"
>> >> Width="87px"></asp:TextBox>
>> >> <IMG id="imgBuscar"
>> >> onclick="javascript:fHelpItm('txtCod')"
>> >> alt=""
>> >> src="../Images/iconBuscar.jpg">
>> >> </EditItemTemplate>
>> >> ==================
>> >>
>> >> the function simplified function is something like this
>> >> =======================
>> >> function fHelpItm(Codigo)
>> >> {
>> >> if confirm(' Do you wanna set a value for ' + Codigo)
>> >> document.forms[0].elements[Codigo].value ='Hello world'
>> >> <<<HERE
>> >> is the problem
>> >> }
>> >> =====================
>> >> jscript says that the name of the control "txtCod" is not an object
>> >> and
>> >> that
>> >> is correct because the name sure is something like
>> >> "Datagrid__ctl2_txtCod"
>> >> so the question is How can I obtain the correct name of the control
>> >>
>> >>
>> >> THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
>> >> bye
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #8

P: n/a
Hi Kostadin

I will do the chage thanks again

bye

"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:C6**********************************@microsof t.com...
I'm glad to help!
Just one recommendation... instead of this code:
For Each c In e.Item.Cells(1).Controls
If TypeOf c Is TextBox Then
s = c.ClientID
End If
Next

use this:
c = e.Item.FindControl("txtCod");
s = c.ClientID

Regards,
Kostadin Kostov

"SergioT" wrote:
HELLO Kostadin

I DID IT!!!!!!!

Thanks a lot, your Idea was the the way!!! I put my code if you wanna
take
a look THANKS again

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim img As New WebControls.Image()
img = e.Item.FindControl("imgBuscar")
If Not img Is Nothing Then
Dim c As Control
Dim s As String
For Each c In e.Item.Cells(1).Controls
If TypeOf c Is TextBox Then
s = c.ClientID
End If
Next
If s.Trim.Length > 0 Then
img.Attributes.Add("onclick", "fHelpItm('" & s & "',
'txtNomItem',
true);")
End If
End If
End Sub
Bye

"Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
message news:5D**********************************@microsof t.com...
>I mean if the needed ID is Datagrid__ctl2_txtCod -
> string id = "Datagrid__ctl" + e.Item.ItemIndex + "_txtCod";
>
> And also - yes, it's applicable. It doesn't matter if you use
> TemplateColumn
> (I almost always use them). The ItemDataBound event doesn't depend on
> the
> column type that you use.
>
> Hope that helps!
> Regards,
> Kostadin Kostov
>
> "SergioT" wrote:
>
>> Hi Kostadin
>>
>> Thanks por the tip, I got only one dub how to do the second point of
>> your
>> sugestion "construct the ID of the TextBox (Datagrid__ctl2_txtCod)"
>> and
>> one
>> more thing, I am using "TemplateColumns" so your first point is
>> aplicable???
>>
>>
>> "Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote in
>> message news:42**********************************@microsof t.com...
>> > The only thing that appears in my mind is:
>> > 1. Handle the ItemDataBound event of the grid
>> > 2. Inside the handler construct the ID of the TextBox
>> > (Datagrid__ctl2_txtCod)
>> > 3. Get your button through e.Item.FindControl("myButton")
>> > 4. Add attribute - myButton.Attributes.Add("onclick",
>> > fHelpItm('Datagrid__ctl2_txtCod'));
>> >
>> > It's quite complicated, but I can't think of better way to achieve
>> > this.
>> > Sorry!
>> > Hope that helps!
>> > Regards,
>> > Kostadin Kostov
>> >
>> > "SergioT" wrote:
>> >
>> >> HI Kostadin
>> >>
>> >> I got the idea, but how can i get the "real name" of the control???
>> >> how
>> >> can
>> >> I "build" the name ????
>> >>
>> >> onclick="javascript:fHelpItm('txtCod')" alt=""
>> >> src="../Images/iconBuscar.jpg">
>> >> ^
>> >> How I must right this part??---------- |
>> >>
>> >> I guess that is the key right?? how to write the control name in
>> >> order
>> >> to
>> >> send to my jscript funcion
>> >>
>> >>
>> >> Thanks
>> >> Bye
>> >>
>> >>
>> >>
>> >>
>> >> "Kostadin Kostov" <Ko************@discussions.microsoft.com> wrote
>> >> in
>> >> message news:31**********************************@microsof t.com...
>> >> > Hi!
>> >> > You cannot get the TextBox using its ID (txtCod), because in
>> >> > datagrid
>> >> > you
>> >> > have many items (here textboxes) with the same ID. But in one
>> >> > page
>> >> > you
>> >> > cannot
>> >> > have two controls with the same ID. So, the framework places some
>> >> > prefix
>> >> > to
>> >> > all the controls. That's why it is like "Datagrid__ctl2_txtCod".
>> >> > If
>> >> > you
>> >> > want
>> >> > to have the textbox available on the client (in js function) you
>> >> > have
>> >> > to
>> >> > use
>> >> > the ID with the prefix
>> >> >
>> >> > Hope that helps!
>> >> > Regards,
>> >> > Kostadin Kostov
>> >> >
>> >> > "SergioT" wrote:
>> >> >
>> >> >> Hi
>> >> >>
>> >> >>
>> >> >> I wanna to create a jscript function that sets the value of a
>> >> >> textbox
>> >> >> into a
>> >> >> datagrid, But the problem is How can I obtain the name of the
>> >> >> textbox
>> >> >> and
>> >> >> send it to my jscript function???? The textbox is in a
>> >> >> TemplateColumn
>> >> >>
>> >> >> The Idea is sent to the funcion the name of the control and then
>> >> >> pass
>> >> >> it
>> >> >> to
>> >> >> another window and then this child window must set the values of
>> >> >> the
>> >> >> control. But for simplicity the problem get reduced to obtain
>> >> >> the
>> >> >> name
>> >> >> of
>> >> >> the textbox
>> >> >>
>> >> >> This is the call of my fHelpItm jscript function, like you see I
>> >> >> associate
>> >> >> the call to onclick event for the IMG control
>> >> >> ==================
>> >> >> <EditItemTemplate>
>> >> >> Codigo<asp:TextBox id="txtCod" runat="server"
>> >> >> Width="87px"></asp:TextBox>
>> >> >> <IMG id="imgBuscar"
>> >> >> onclick="javascript:fHelpItm('txtCod')"
>> >> >> alt=""
>> >> >> src="../Images/iconBuscar.jpg">
>> >> >> </EditItemTemplate>
>> >> >> ==================
>> >> >>
>> >> >> the function simplified function is something like this
>> >> >> =======================
>> >> >> function fHelpItm(Codigo)
>> >> >> {
>> >> >> if confirm(' Do you wanna set a value for ' + Codigo)
>> >> >> document.forms[0].elements[Codigo].value ='Hello world'
>> >> >> <<<HERE
>> >> >> is the problem
>> >> >> }
>> >> >> =====================
>> >> >> jscript says that the name of the control "txtCod" is not an
>> >> >> object
>> >> >> and
>> >> >> that
>> >> >> is correct because the name sure is something like
>> >> >> "Datagrid__ctl2_txtCod"
>> >> >> so the question is How can I obtain the correct name of the
>> >> >> control
>> >> >>
>> >> >>
>> >> >> THANKSSSSSSS FOR YOUR HELP because this is getting me crazy!!!
>> >> >> bye
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #9

P: n/a


hi..
i tried implementing the same code.
i get teh correct id of the textbox in the datagird.. but
img.Attributes.Add("onclick","GetAd('"+ s + "');");
at the above line i get an error..
Object reference null..
( i 'm using C#)
Please let me know .. i 'm struggling with this code for past 3 days

*** Sent via Developersdex http://www.developersdex.com ***
Dec 15 '05 #10

P: n/a
RCS
If you do a View Source on the outputted page - does the code look correct?

"shamila thakur" <tr*******@yahoo.com> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...


hi..
i tried implementing the same code.
i get teh correct id of the textbox in the datagird.. but
img.Attributes.Add("onclick","GetAd('"+ s + "');");
at the above line i get an error..
Object reference null..
( i 'm using C#)
Please let me know .. i 'm struggling with this code for past 3 days

*** Sent via Developersdex http://www.developersdex.com ***

Dec 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.