Call client script to update an item in a data grid

L

LehrSJ

Is there a way to run client script function or procedure to update data in a
data grid? Say I have a textbox in the datagrid. The user enters some data.
After exiting the textbox I'd like a client script to change the new value to
all upper case or if it's a date format it a certain way.

thanks
 
E

Eliyahu Goldin

Sure, you just need to setup client-side events. One way is to handle the
grid's ItemDataBound event. In the event you get access to the item (row)
elements and use their Attributes collection for adding client-side event
handlers.

Eliyahu
 
S

Steven Cheng[MSFT]

Hi LehrSJ,

As Eliyahu has mentioned, we can use the DataGrid's ItemDataBound or
ItemCreated event to add the clientside script handler for the certain
controls in the DataGrid Column.... e.g:

Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem
Dim myDeleteButton As Button
myDeleteButton = e.Item.FindControl("btnDelete")
myDeleteButton.Attributes.Add("onclick",_
"return confirm('Are you sure you want to delete this company?');")

End Select
End Sub

the above code programmatically add a confirm script for a button in a
datagrid template column....

Also, you can use predefined script functions in aspx page also......

Hope helps.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Eliyahu Goldin" <[email protected]>
| References: <[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Sun, 1 Jan 2006 10:04:22 +0200
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: 212.143.94.3
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Sure, you just need to setup client-side events. One way is to handle the
| grid's ItemDataBound event. In the event you get access to the item (row)
| elements and use their Attributes collection for adding client-side event
| handlers.
|
| Eliyahu
|
| | > Is there a way to run client script function or procedure to update
data
| > in a
| > data grid? Say I have a textbox in the datagrid. The user enters some
| > data.
| > After exiting the textbox I'd like a client script to change the new
value
| > to
| > all upper case or if it's a date format it a certain way.
| >
| > thanks
| > --
| > LehrSJ
|
|
|
 
S

Steven Cheng[MSFT]

Of course GridView, DetailsView and most other template databound controls
can utilize such means.... Also, there is another method for injecting
clientside script for such inner controls:

We can declare a "PreRender" event handler for those controls (a
TextBox....), e.g:

==============
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%#
Eval("id") %>'></asp:Label><br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%#
Bind("name") %>' OnPreRender="TextBox_OnPreRender">
</asp:TextBox><br />
================

"TextBox_OnPreRender" is a non-private method defined in the Page's
codebehind class, and we put the script registering code in that
method......

Using this means can avoid intercepting the DataBound control's ItemCreated
or ItemDataBound event, only concencrate on the inner control we care
about....

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Thread-Topic: Call client script to update an item in a data grid
| thread-index: AcYQdR5oMm/Eg1pxS16acJmte72Btw==
| X-WBNR-Posting-Host: 70.118.231.121
| From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Tue, 3 Jan 2006 06:51:03 -0800
| Lines: 84
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15004
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Thanks. Is it possible to do this with a GridView or DetailsView?
| --
| LehrSJ
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi LehrSJ,
| >
| > As Eliyahu has mentioned, we can use the DataGrid's ItemDataBound or
| > ItemCreated event to add the clientside script handler for the certain
| > controls in the DataGrid Column.... e.g:
| >
| > Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
| > Select Case e.Item.ItemType
| > Case ListItemType.Item, ListItemType.AlternatingItem,
| > ListItemType.EditItem
| > Dim myDeleteButton As Button
| > myDeleteButton = e.Item.FindControl("btnDelete")
| > myDeleteButton.Attributes.Add("onclick",_
| > "return confirm('Are you sure you want to delete this company?');")
| >
| > End Select
| > End Sub
| >
| > the above code programmatically add a confirm script for a button in a
| > datagrid template column....
| >
| > Also, you can use predefined script functions in aspx page also......
| >
| > Hope helps.
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Eliyahu Goldin" <[email protected]>
| > | References: <[email protected]>
| > | Subject: Re: Call client script to update an item in a data grid
| > | Date: Sun, 1 Jan 2006 10:04:22 +0200
| > | Lines: 22
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: 212.143.94.3
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Sure, you just need to setup client-side events. One way is to handle
the
| > | grid's ItemDataBound event. In the event you get access to the item
(row)
| > | elements and use their Attributes collection for adding client-side
event
| > | handlers.
| > |
| > | Eliyahu
| > |
| > | | > | > Is there a way to run client script function or procedure to update
| > data
| > | > in a
| > | > data grid? Say I have a textbox in the datagrid. The user enters
some
| > | > data.
| > | > After exiting the textbox I'd like a client script to change the
new
| > value
| > | > to
| > | > all upper case or if it's a date format it a certain way.
| > | >
| > | > thanks
| > | > --
| > | > LehrSJ
| > |
| > |
| > |
| >
| >
|
 
L

LehrSJ

Thanks for the information but I don't see what to do in the PreRender event
to add the attribute to the textbox for the client script to call. In the
edit template field the textbox name is EmpName. So my PreRender event looks
like:

Protected Sub EmpName_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs)

But there is no "e.item" option to refer to the item like the example you
had for the datagrid, DataGridItemEventArgs.
--
LehrSJ


Steven Cheng said:
Of course GridView, DetailsView and most other template databound controls
can utilize such means.... Also, there is another method for injecting
clientside script for such inner controls:

We can declare a "PreRender" event handler for those controls (a
TextBox....), e.g:

==============
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%#
Eval("id") %>'></asp:Label><br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%#
Bind("name") %>' OnPreRender="TextBox_OnPreRender">
</asp:TextBox><br />
================

"TextBox_OnPreRender" is a non-private method defined in the Page's
codebehind class, and we put the script registering code in that
method......

Using this means can avoid intercepting the DataBound control's ItemCreated
or ItemDataBound event, only concencrate on the inner control we care
about....

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Thread-Topic: Call client script to update an item in a data grid
| thread-index: AcYQdR5oMm/Eg1pxS16acJmte72Btw==
| X-WBNR-Posting-Host: 70.118.231.121
| From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Tue, 3 Jan 2006 06:51:03 -0800
| Lines: 84
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15004
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Thanks. Is it possible to do this with a GridView or DetailsView?
| --
| LehrSJ
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi LehrSJ,
| >
| > As Eliyahu has mentioned, we can use the DataGrid's ItemDataBound or
| > ItemCreated event to add the clientside script handler for the certain
| > controls in the DataGrid Column.... e.g:
| >
| > Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
| > Select Case e.Item.ItemType
| > Case ListItemType.Item, ListItemType.AlternatingItem,
| > ListItemType.EditItem
| > Dim myDeleteButton As Button
| > myDeleteButton = e.Item.FindControl("btnDelete")
| > myDeleteButton.Attributes.Add("onclick",_
| > "return confirm('Are you sure you want to delete this company?');")
| >
| > End Select
| > End Sub
| >
| > the above code programmatically add a confirm script for a button in a
| > datagrid template column....
| >
| > Also, you can use predefined script functions in aspx page also......
| >
| > Hope helps.
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | From: "Eliyahu Goldin" <[email protected]>
| > | References: <[email protected]>
| > | Subject: Re: Call client script to update an item in a data grid
| > | Date: Sun, 1 Jan 2006 10:04:22 +0200
| > | Lines: 22
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: 212.143.94.3
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Sure, you just need to setup client-side events. One way is to handle
the
| > | grid's ItemDataBound event. In the event you get access to the item
(row)
| > | elements and use their Attributes collection for adding client-side
event
| > | handlers.
| > |
| > | Eliyahu
| > |
| > | | > | > Is there a way to run client script function or procedure to update
| > data
| > | > in a
| > | > data grid? Say I have a textbox in the datagrid. The user enters
some
| > | > data.
| > | > After exiting the textbox I'd like a client script to change the
new
| > value
| > | > to
| > | > all upper case or if it's a date format it a certain way.
| > | >
| > | > thanks
| > | > --
| > | > LehrSJ
| > |
| > |
| > |
| >
| >
|
 
S

Steven Cheng[MSFT]

Thanks for your response LehrSJ,

Surely the TextBox's PreRender event won't contains the same event Argument
like DataGird's ItemDataBound or itemCreated, however, when we just need to
add some attributes which only related to the Textbox's own value(number
formatting or range validation scripts...), PreRender will be a good event
since it is only associated with the textbox we want to hook.... Also,
PreRendder event is the last event we can use to change controls' states
before rendering out(so the page's control structure should have been
construted well at that time...)

And if you want your registered script also depend on some info on the
DataGrid's bound data item or other cells' value, I think we have to use
ItemDataBound event ....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Thread-Topic: Call client script to update an item in a data grid
| thread-index: AcYTlFRiiNBKU6J8SzCuVoP2xTc+vQ==
| X-WBNR-Posting-Host: 70.118.231.121
| From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Sat, 7 Jan 2006 06:12:02 -0800
| Lines: 173
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15020
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Thanks for the information but I don't see what to do in the PreRender
event
| to add the attribute to the textbox for the client script to call. In
the
| edit template field the textbox name is EmpName. So my PreRender event
looks
| like:
|
| Protected Sub EmpName_PreRender(ByVal sender As Object, ByVal e As
| System.EventArgs)
|
| But there is no "e.item" option to refer to the item like the example you
| had for the datagrid, DataGridItemEventArgs.
| --
| LehrSJ
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Of course GridView, DetailsView and most other template databound
controls
| > can utilize such means.... Also, there is another method for
injecting
| > clientside script for such inner controls:
| >
| > We can declare a "PreRender" event handler for those controls (a
| > TextBox....), e.g:
| >
| > ==============
| > <EditItemTemplate>
| > id:
| > <asp:Label ID="idLabel1" runat="server" Text='<%#
| > Eval("id") %>'></asp:Label><br />
| > name:
| > <asp:TextBox ID="nameTextBox" runat="server" Text='<%#
| > Bind("name") %>' OnPreRender="TextBox_OnPreRender">
| > </asp:TextBox><br />
| > ================
| >
| > "TextBox_OnPreRender" is a non-private method defined in the Page's
| > codebehind class, and we put the script registering code in that
| > method......
| >
| > Using this means can avoid intercepting the DataBound control's
ItemCreated
| > or ItemDataBound event, only concencrate on the inner control we care
| > about....
| >
| > Hope also helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: Call client script to update an item in a data grid
| > | thread-index: AcYQdR5oMm/Eg1pxS16acJmte72Btw==
| > | X-WBNR-Posting-Host: 70.118.231.121
| > | From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Subject: Re: Call client script to update an item in a data grid
| > | Date: Tue, 3 Jan 2006 06:51:03 -0800
| > | Lines: 84
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:15004
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Thanks. Is it possible to do this with a GridView or DetailsView?
| > | --
| > | LehrSJ
| > |
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Hi LehrSJ,
| > | >
| > | > As Eliyahu has mentioned, we can use the DataGrid's ItemDataBound
or
| > | > ItemCreated event to add the clientside script handler for the
certain
| > | > controls in the DataGrid Column.... e.g:
| > | >
| > | > Sub DataGrid_ItemCreated(Sender As Object, e As
DataGridItemEventArgs)
| > | > Select Case e.Item.ItemType
| > | > Case ListItemType.Item, ListItemType.AlternatingItem,
| > | > ListItemType.EditItem
| > | > Dim myDeleteButton As Button
| > | > myDeleteButton = e.Item.FindControl("btnDelete")
| > | > myDeleteButton.Attributes.Add("onclick",_
| > | > "return confirm('Are you sure you want to delete this
company?');")
| > | >
| > | > End Select
| > | > End Sub
| > | >
| > | > the above code programmatically add a confirm script for a button
in a
| > | > datagrid template column....
| > | >
| > | > Also, you can use predefined script functions in aspx page
also......
| > | >
| > | > Hope helps.
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | > --------------------
| > | > | From: "Eliyahu Goldin" <[email protected]>
| > | > | References: <[email protected]>
| > | > | Subject: Re: Call client script to update an item in a data grid
| > | > | Date: Sun, 1 Jan 2006 10:04:22 +0200
| > | > | Lines: 22
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | > | Message-ID: <[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: 212.143.94.3
| > | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| > | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Sure, you just need to setup client-side events. One way is to
handle
| > the
| > | > | grid's ItemDataBound event. In the event you get access to the
item
| > (row)
| > | > | elements and use their Attributes collection for adding
client-side
| > event
| > | > | handlers.
| > | > |
| > | > | Eliyahu
| > | > |
| > | > | | > | > | > Is there a way to run client script function or procedure to
update
| > | > data
| > | > | > in a
| > | > | > data grid? Say I have a textbox in the datagrid. The user
enters
| > some
| > | > | > data.
| > | > | > After exiting the textbox I'd like a client script to change
the
| > new
| > | > value
| > | > | > to
| > | > | > all upper case or if it's a date format it a certain way.
| > | > | >
| > | > | > thanks
| > | > | > --
| > | > | > LehrSJ
| > | > |
| > | > |
| > | > |
| > | >
| > | >
| > |
| >
| >
|
 
L

LehrSJ

I finally realized what I was doing wrong. I got it to work with the
ItemCreated event. My problem was that the textbox only exists when the
current mode is edit. I wasn't checking for this and was trying to add the
attribute when in readonly mode. So I got an error. It's working fine now.
Thanks.
--
LehrSJ


Steven Cheng said:
Thanks for your response LehrSJ,

Surely the TextBox's PreRender event won't contains the same event Argument
like DataGird's ItemDataBound or itemCreated, however, when we just need to
add some attributes which only related to the Textbox's own value(number
formatting or range validation scripts...), PreRender will be a good event
since it is only associated with the textbox we want to hook.... Also,
PreRendder event is the last event we can use to change controls' states
before rendering out(so the page's control structure should have been
construted well at that time...)

And if you want your registered script also depend on some info on the
DataGrid's bound data item or other cells' value, I think we have to use
ItemDataBound event ....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Thread-Topic: Call client script to update an item in a data grid
| thread-index: AcYTlFRiiNBKU6J8SzCuVoP2xTc+vQ==
| X-WBNR-Posting-Host: 70.118.231.121
| From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Sat, 7 Jan 2006 06:12:02 -0800
| Lines: 173
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15020
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Thanks for the information but I don't see what to do in the PreRender
event
| to add the attribute to the textbox for the client script to call. In
the
| edit template field the textbox name is EmpName. So my PreRender event
looks
| like:
|
| Protected Sub EmpName_PreRender(ByVal sender As Object, ByVal e As
| System.EventArgs)
|
| But there is no "e.item" option to refer to the item like the example you
| had for the datagrid, DataGridItemEventArgs.
| --
| LehrSJ
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Of course GridView, DetailsView and most other template databound
controls
| > can utilize such means.... Also, there is another method for
injecting
| > clientside script for such inner controls:
| >
| > We can declare a "PreRender" event handler for those controls (a
| > TextBox....), e.g:
| >
| > ==============
| > <EditItemTemplate>
| > id:
| > <asp:Label ID="idLabel1" runat="server" Text='<%#
| > Eval("id") %>'></asp:Label><br />
| > name:
| > <asp:TextBox ID="nameTextBox" runat="server" Text='<%#
| > Bind("name") %>' OnPreRender="TextBox_OnPreRender">
| > </asp:TextBox><br />
| > ================
| >
| > "TextBox_OnPreRender" is a non-private method defined in the Page's
| > codebehind class, and we put the script registering code in that
| > method......
| >
| > Using this means can avoid intercepting the DataBound control's
ItemCreated
| > or ItemDataBound event, only concencrate on the inner control we care
| > about....
| >
| > Hope also helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: Call client script to update an item in a data grid
| > | thread-index: AcYQdR5oMm/Eg1pxS16acJmte72Btw==
| > | X-WBNR-Posting-Host: 70.118.231.121
| > | From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Subject: Re: Call client script to update an item in a data grid
| > | Date: Tue, 3 Jan 2006 06:51:03 -0800
| > | Lines: 84
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:15004
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Thanks. Is it possible to do this with a GridView or DetailsView?
| > | --
| > | LehrSJ
| > |
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Hi LehrSJ,
| > | >
| > | > As Eliyahu has mentioned, we can use the DataGrid's ItemDataBound
or
| > | > ItemCreated event to add the clientside script handler for the
certain
| > | > controls in the DataGrid Column.... e.g:
| > | >
| > | > Sub DataGrid_ItemCreated(Sender As Object, e As
DataGridItemEventArgs)
| > | > Select Case e.Item.ItemType
| > | > Case ListItemType.Item, ListItemType.AlternatingItem,
| > | > ListItemType.EditItem
| > | > Dim myDeleteButton As Button
| > | > myDeleteButton = e.Item.FindControl("btnDelete")
| > | > myDeleteButton.Attributes.Add("onclick",_
| > | > "return confirm('Are you sure you want to delete this
company?');")
| > | >
| > | > End Select
| > | > End Sub
| > | >
| > | > the above code programmatically add a confirm script for a button
in a
| > | > datagrid template column....
| > | >
| > | > Also, you can use predefined script functions in aspx page
also......
| > | >
| > | > Hope helps.
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | > --------------------
| > | > | From: "Eliyahu Goldin" <[email protected]>
| > | > | References: <[email protected]>
| > | > | Subject: Re: Call client script to update an item in a data grid
| > | > | Date: Sun, 1 Jan 2006 10:04:22 +0200
| > | > | Lines: 22
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | > | Message-ID: <[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: 212.143.94.3
| > | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| > | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Sure, you just need to setup client-side events. One way is to
handle
| > the
| > | > | grid's ItemDataBound event. In the event you get access to the
item
| > (row)
| > | > | elements and use their Attributes collection for adding
client-side
| > event
| > | > | handlers.
| > | > |
| > | > | Eliyahu
| > | > |
| > | > | | > | > | > Is there a way to run client script function or procedure to
update
| > | > data
| > | > | > in a
| > | > | > data grid? Say I have a textbox in the datagrid. The user
enters
| > some
| > | > | > data.
| > | > | > After exiting the textbox I'd like a client script to change
the
| > new
| > | > value
| > | > | > to
| > | > | > all upper case or if it's a date format it a certain way.
| > | > | >
| > | > | > thanks
| > | > | > --
| > | > | > LehrSJ
| > | > |
| > | > |
| > | > |
| > | >
| > | >
| > |
| >
| >
|
 
S

Steven Cheng[MSFT]

Thanks for your followup.

Glad that you've got it working.

Have a good day!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Call client script to update an item in a data grid
| thread-index: AcYV7ife9MRNssIKRDOhSulEpS82aQ==
| X-WBNR-Posting-Host: 70.118.231.121
| From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Call client script to update an item in a data grid
| Date: Tue, 10 Jan 2006 06:00:04 -0800
| Lines: 266
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:15040
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| I finally realized what I was doing wrong. I got it to work with the
| ItemCreated event. My problem was that the textbox only exists when the
| current mode is edit. I wasn't checking for this and was trying to add
the
| attribute when in readonly mode. So I got an error. It's working fine
now.
| Thanks.
| --
| LehrSJ
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Thanks for your response LehrSJ,
| >
| > Surely the TextBox's PreRender event won't contains the same event
Argument
| > like DataGird's ItemDataBound or itemCreated, however, when we just
need to
| > add some attributes which only related to the Textbox's own
value(number
| > formatting or range validation scripts...), PreRender will be a good
event
| > since it is only associated with the textbox we want to hook....
Also,
| > PreRendder event is the last event we can use to change controls'
states
| > before rendering out(so the page's control structure should have been
| > construted well at that time...)
| >
| > And if you want your registered script also depend on some info on the
| > DataGrid's bound data item or other cells' value, I think we have to
use
| > ItemDataBound event ....
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: Call client script to update an item in a data grid
| > | thread-index: AcYTlFRiiNBKU6J8SzCuVoP2xTc+vQ==
| > | X-WBNR-Posting-Host: 70.118.231.121
| > | From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | Subject: Re: Call client script to update an item in a data grid
| > | Date: Sat, 7 Jan 2006 06:12:02 -0800
| > | Lines: 173
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:15020
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Thanks for the information but I don't see what to do in the
PreRender
| > event
| > | to add the attribute to the textbox for the client script to call.
In
| > the
| > | edit template field the textbox name is EmpName. So my PreRender
event
| > looks
| > | like:
| > |
| > | Protected Sub EmpName_PreRender(ByVal sender As Object, ByVal e As
| > | System.EventArgs)
| > |
| > | But there is no "e.item" option to refer to the item like the example
you
| > | had for the datagrid, DataGridItemEventArgs.
| > | --
| > | LehrSJ
| > |
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Of course GridView, DetailsView and most other template databound
| > controls
| > | > can utilize such means.... Also, there is another method for
| > injecting
| > | > clientside script for such inner controls:
| > | >
| > | > We can declare a "PreRender" event handler for those controls (a
| > | > TextBox....), e.g:
| > | >
| > | > ==============
| > | > <EditItemTemplate>
| > | > id:
| > | > <asp:Label ID="idLabel1" runat="server" Text='<%#
| > | > Eval("id") %>'></asp:Label><br />
| > | > name:
| > | > <asp:TextBox ID="nameTextBox" runat="server"
Text='<%#
| > | > Bind("name") %>' OnPreRender="TextBox_OnPreRender">
| > | > </asp:TextBox><br />
| > | > ================
| > | >
| > | > "TextBox_OnPreRender" is a non-private method defined in the Page's
| > | > codebehind class, and we put the script registering code in that
| > | > method......
| > | >
| > | > Using this means can avoid intercepting the DataBound control's
| > ItemCreated
| > | > or ItemDataBound event, only concencrate on the inner control we
care
| > | > about....
| > | >
| > | > Hope also helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Thread-Topic: Call client script to update an item in a data grid
| > | > | thread-index: AcYQdR5oMm/Eg1pxS16acJmte72Btw==
| > | > | X-WBNR-Posting-Host: 70.118.231.121
| > | > | From: =?Utf-8?B?TGVoclNK?= <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > <[email protected]>
| > | > | Subject: Re: Call client script to update an item in a data grid
| > | > | Date: Tue, 3 Jan 2006 06:51:03 -0800
| > | > | Lines: 84
| > | > | Message-ID: <[email protected]>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain;
| > | > | charset="Utf-8"
| > | > | Content-Transfer-Encoding: 7bit
| > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | Content-Class: urn:content-classes:message
| > | > | Importance: normal
| > | > | Priority: normal
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:15004
| > | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Thanks. Is it possible to do this with a GridView or DetailsView?
| > | > | --
| > | > | LehrSJ
| > | > |
| > | > |
| > | > | "Steven Cheng[MSFT]" wrote:
| > | > |
| > | > | > Hi LehrSJ,
| > | > | >
| > | > | > As Eliyahu has mentioned, we can use the DataGrid's
ItemDataBound
| > or
| > | > | > ItemCreated event to add the clientside script handler for the
| > certain
| > | > | > controls in the DataGrid Column.... e.g:
| > | > | >
| > | > | > Sub DataGrid_ItemCreated(Sender As Object, e As
| > DataGridItemEventArgs)
| > | > | > Select Case e.Item.ItemType
| > | > | > Case ListItemType.Item, ListItemType.AlternatingItem,
| > | > | > ListItemType.EditItem
| > | > | > Dim myDeleteButton As Button
| > | > | > myDeleteButton = e.Item.FindControl("btnDelete")
| > | > | > myDeleteButton.Attributes.Add("onclick",_
| > | > | > "return confirm('Are you sure you want to delete this
| > company?');")
| > | > | >
| > | > | > End Select
| > | > | > End Sub
| > | > | >
| > | > | > the above code programmatically add a confirm script for a
button
| > in a
| > | > | > datagrid template column....
| > | > | >
| > | > | > Also, you can use predefined script functions in aspx page
| > also......
| > | > | >
| > | > | > Hope helps.
| > | > | >
| > | > | > Steven Cheng
| > | > | > Microsoft Online Support
| > | > | >
| > | > | > Get Secure! www.microsoft.com/security
| > | > | > (This posting is provided "AS IS", with no warranties, and
confers
| > no
| > | > | > rights.)
| > | > | > --------------------
| > | > | > | From: "Eliyahu Goldin" <[email protected]>
| > | > | > | References:
<[email protected]>
| > | > | > | Subject: Re: Call client script to update an item in a data
grid
| > | > | > | Date: Sun, 1 Jan 2006 10:04:22 +0200
| > | > | > | Lines: 22
| > | > | > | X-Priority: 3
| > | > | > | X-MSMail-Priority: Normal
| > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | > | > | X-RFC2646: Format=Flowed; Original
| > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | > | > | Message-ID: <[email protected]>
| > | > | > | Newsgroups:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | > | NNTP-Posting-Host: 212.143.94.3
| > | > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14995
| > | > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | > |
| > | > | > | Sure, you just need to setup client-side events. One way is
to
| > handle
| > | > the
| > | > | > | grid's ItemDataBound event. In the event you get access to
the
| > item
| > | > (row)
| > | > | > | elements and use their Attributes collection for adding
| > client-side
| > | > event
| > | > | > | handlers.
| > | > | > |
| > | > | > | Eliyahu
| > | > | > |
| > | > | > | | > | > | > | > Is there a way to run client script function or procedure
to
| > update
| > | > | > data
| > | > | > | > in a
| > | > | > | > data grid? Say I have a textbox in the datagrid. The user
| > enters
| > | > some
| > | > | > | > data.
| > | > | > | > After exiting the textbox I'd like a client script to
change
| > the
| > | > new
| > | > | > value
| > | > | > | > to
| > | > | > | > all upper case or if it's a date format it a certain way.
| > | > | > | >
| > | > | > | > thanks
| > | > | > | > --
| > | > | > | > LehrSJ
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > | >
| > | > |
| > | >
| > | >
| > |
| >
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top