DataGrid编辑了行和jScript [英] DataGrid edited row and jScript

查看:37
本文介绍了DataGrid编辑了行和jScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想创建一个jscript函数,将文本框的值设置为

数据网格,但问题是如何获取该名称的文本框和

将它发送到我的jscript函数????文本框在一个TemplateColumn中


将Idea发送给函数控件的名称,然后将其传递给

另一个窗口然后这个子窗口必须设置

控件的值。但为了简单起见,问题变得简陋,以获得名称

文本框


这是我的fHelpItm jscript函数的调用,就像你看到我关联

调用IMG控件的onclick事件

==================

< EditItemTemplate>

Codigo< asp:TextBox id =" txtCod" runat =" server"

Width =" 87px">< / asp:TextBox>

< IMG id =" imgBuscar"的onclick = QUOT;的JavaScript的 的:fHelpItm( txtCod)" alt =""

src =" ../ Images / iconBuscar.jpg">

< / EditItemTemplate>

==================


函数简化函数是这样的

==== ===================

功能fHelpItm(Codigo)

{

if确认(''你想为''+ Codigo设置一个值)

document.forms [0] .elements [Codigo] .value =''Hello world''<<<这里

就是问题

}

=====================

jscript说控件的名称是txtCod。不是一个对象,并且

是正确的,因为名称肯定是Datagrid__ctl2_txtCod

所以问题是如何获得控件的正确名称<谢谢你的帮助,因为这让我很生气!!!

再见

解决方案

嗨!

您无法使用其ID(txtCod)获取TextBox,因为在数据网格中,您需要具有相同ID的许多项目(此处为文本框)。但是在一个页面中你不能

有两个具有相同ID的控件。因此,框架为所有控件添加了一些前缀

。这就是为什么它就像Datagrid__ctl2_txtCod。如果你想要

在客户端上使用文本框(在js函数中)你必须使用

带有前缀的ID


希望有所帮助!

问候,

Kostadin Kostov


" SergioT"写道:



我想创建一个jscript函数,将文本框的值设置为
数据网格,但问题是如何我可以获取文本框的名称并将其发送到我的jscript函数吗?文本框位于TemplateColumn中

将Idea发送给函数控件的名称,然后将其传递给另一个窗口,然后这个子窗口必须设置
这是我的fHelpItm jscript函数的调用,就像你看到我联系
调用onclick事件用于IMG控制
==================
< EditItemTemplate>
Codigo< asp:TextBox id =" txtCod" runat =" server"
Width =" 87px">< / asp:TextBox>
< IMG id =" imgBuscar"的onclick = QUOT;的JavaScript的 的:fHelpItm( txtCod)" alt =""
src =" ../ Images / iconBuscar.jpg">
< / EditItemTemplate>
============ ======

函数简化函数就是这样的东西
======================= <功能fHelpItm(Codigo)
{
如果确认(''你想为''+ Codigo设置一个值)
document.forms [0] .elements [Codigo]。 value =''Hello world''<<<< HERE
是问题
}
=================== ==
jscript说控件的名称是txtCod。不是一个对象而且
是正确的,因为名称确实类似于Datagrid__ctl2_txtCod
所以问题是如何获得控件的正确名称

THANKSSSSSSS为了你的帮助因为这让我疯了!!!
再见



HI Kostadin


我明白了,但我怎样才能得到真实姓名。控制???怎么能

我建立名字????


onclick =" javascript :fHelpItm(''txtCod'')" alt =""

src =" ../ Images / iconBuscar.jpg">

^

我必须如何正确这部分?? ---------- |


我猜这是关键吗?如何写控制名称以便

发送给我的jscript函数

谢谢

再见



" Kostadin Kostov" <柯************ @ discussions.microsoft.com>写在

消息新闻:31 ********************************** @ microsof t.com ...

嗨!
你无法使用它的ID(txtCod)获取TextBox,因为在datagrid中你有很多项目(这里是文本框) ID。但是在一个页面中你不能拥有两个具有相同ID的控件。因此,框架为所有控件添加了一些前缀
。这就是为什么它就像Datagrid__ctl2_txtCod。如果您想要在客户端上使用文本框(在js函数中),您必须使用带有前缀的ID

希望这有帮助!
问候,
Kostadin Kostov

SergioT写道:



我想创建一个jscript函数,将文本框的值设置为
数据网格,但是问题是如何获取文本框的名称并将其发送到我的jscript函数????文本框在TemplateColumn中

将Idea发送给函数的控件名称,然后将其传递给
另一个窗口,然后这个子窗口必须设置值的控制。但为了简单起见,问题变得简陋,以获得文本框的名称

这是我的fHelpItm jscript函数的调用,就像你看到我
关联
调用onclick事件进行IMG控制
==================
< 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>
==================

函数简化函数是这样的
=======================
功能fHelpItm(Codigo)
{
如果确认(''做你想为''+ Codigo设置一个值
document.forms [0] .elements [Codigo] .value =''Hello world''
<<< HERE
是问题
}
=====================
jscript说控件的名称是txtCod。不是一个对象,

是正确的,因为名称肯定是类似
Datagrid__ctl2_txtCod
所以问题是如何获得控件的正确名称<为你的帮助感谢谢谢,因为这让我很生气!!!
再见



< blockquote>我脑海中唯一出现的是:

1.处理网格的ItemDataBound事件

2.在处理程序内部构造TextBox的ID(Datagrid__ctl2_txtCod )

3.通过e.Item.FindControl(" myButton")获取按钮

4.添加属性 - myButton.Attributes.Add(" onclick",

fHelpItm(''Datagrid__ctl2_txtCod''));


这很复杂,但我想不出更好的方法来实现这个目标。

对不起!

希望有所帮助!

问候,

Kostadin Kostov

" SergioT"写道:

HI Kostadin

我明白了,但我怎样才能得到真实姓名。控制???我怎么能建立名称????

onclick =" javascript :fHelpItm(''txtCod'')" alt =""
src =" ../ Images / iconBuscar.jpg">
^
我该如何正确对待这部分?-------- - |

我猜这是关键吗?如何写控制名称以便发送给我的jscript函数

谢谢
再见

Kostadin Kostov <柯************ @ discussions.microsoft.com>在消息新闻中写道:31 ********************************** @ microsof t.com。 ..

嗨!
你不能使用它的ID(txtCod)获取TextBox,因为在datagrid中你有许多具有相同ID的项目(这里是文本框)。但是在一个页面中你不能拥有两个具有相同ID的控件。因此,框架为所有控件添加了一些前缀
。这就是为什么它就像Datagrid__ctl2_txtCod。如果您想要在客户端上使用文本框(在js函数中),您必须使用带有前缀的ID

希望这有帮助!
问候,
Kostadin Kostov

SergioT写道:



我想创建一个jscript函数,将文本框的值设置为
数据网格,但是问题是如何获取文本框的名称并将其发送到我的jscript函数????文本框在TemplateColumn中

将Idea发送给函数的控件名称,然后将其传递给
另一个窗口,然后这个子窗口必须设置值的控制。但为了简单起见,问题变得简陋,以获得文本框的名称

这是我的fHelpItm jscript函数的调用,就像你看到我
关联
调用onclick事件进行IMG控制
==================
< 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>
==================

函数简化函数是这样的
=======================
功能fHelpItm(Codigo)
{
如果确认(''做你想为''+ Codigo设置一个值
document.forms [0] .elements [Codigo] .value =''Hello world''
<<< HERE
是问题
}
=====================
jscript说控件的名称是txtCod。不是一个对象,

是正确的,因为名称肯定是类似
Datagrid__ctl2_txtCod
所以问题是如何获得控件的正确名称<为你的帮助感谢谢谢,因为这让我很生气!!!
再见




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!
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




这篇关于DataGrid编辑了行和jScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆