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 10 1312
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
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
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
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 >> >> >>
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 >> >> >>
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 >> >> >> >> >> >> >> >> >>
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 >> >> >> >> >> >> >> >> >>
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 >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
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 ***
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 *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tom |
last post by:
Hi,
I have been through all kinds of documentation on the datagrid and
dataviews. I have many expensive books that I have looked through. But
nothing has really helped. I want to find out and...
|
by: localhost |
last post by:
When I go into Edit mode on a datagrid, I would like to
add a single column to the edited row and display a
hyperlink. If I use the code below, I get a delete
linkbutton in every row, when I only...
|
by: Janaka |
last post by:
Hi All,
I'm having a problem with Page Output caching on a page that contains a
DataGrid. Basically the page pulls up some data for sales information from
the DB. Some of this has to be...
|
by: BW |
last post by:
Hello,
I am attempting to to take edited values from a datagrid control and update
the underlying database. Problem is that some of the edited values don quite
seem to make it to my update sub....
|
by: Suzanne |
last post by:
Hi all,
I'm having problems with datagrids and the currentcellchanged event.
My problem is this: I have a datagrid on a form, if the user changes
the text in a cell on the datagrid then tries to...
|
by: Doug Bell |
last post by:
Hi
I have a datagrid with a combo box,
I need to populate the combo with data dependant on the record value.
eg for record 1, field Warehouse = 2R so combo would allow selection of
locations...
|
by: Antonio |
last post by:
I am having a problem finding out how to page a datagrid.
I have the procedure for moving from page to page as:
private void changePage(object source,...
|
by: rn5a |
last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the...
|
by: SanjayKumarDey |
last post by:
I have a vb.net datagrid bound to a dataview on a windows form. I want to
use the datagrid to display and filter a list of items , but since the data
is complex, I don't want the user to edit the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
| |