Programmatically databinding textboxes to a datagrid

S

Scott McNair

Hi,

I've got a dataset that I'm generating through a webservice. I would like
to instantiate one of the tables in the set as a grid. Some of the columns
in that grid should be editable via a textbox control, and I'd also like to
have a checkbox to mark rows for delete, and some button controls to add
rows, update the data, or delete rows. Example:

DEL? FirstName LastName Birthdate ID (this is hidden)
---- ---------- ----------- ----------- ---
[X] [Han ] [Solo ] [2/27/1973] 1
[ ] [Leia ] [Organa ] [4/13/1971] 2
[ ] [Luke ] [Skywalker] [4/13/1971] 3

[DELETE SELECTED] [ADD NEW ROW] [UPDATE TABLE]

My immediate solution was to create a datagrid and then create some
template columns to contain the data. My problem is that I can't figure
out how databound columns can be templates, nor how template columns can be
databound. So I can either create columns with textboxes inside their
cells, or I can create columns with data in them, but not both.

I guess in a nutshell, my question is this: how do I create an editable,
bound datagrid? I've seen some examples of creating a class that inherits
ITemplate, but all the examples I've seen were in C# and although I can
comprehend C# on a basic level, large amounts of strange code can get me
lost. Plus, I'm not sure if those routes were the route I needed to take.

Please keep in mind the following:

* Since I'm pulling the data from a webservice, there's no way (that I know
of at least) to create the datasource and bind it at runtime; instead I
have to establish the connection manually inside the codebehind.

* I must be able to actually mine the changes to the datagrid on the
server, by iterating thru the rows and then sending the new data back up to
the webservice so that it can be updated at the data source. So the
textboxes should have function as well as form.

* I need the ability to do this thru AJAX (specifically thru the MagicAJAX
control at www.magicajax.net). The whole reason I'm having to research
this path is because my prior attempt (using an Infragistics grid) worked
perfectly EXCEPT for the fact that it would not work thru AJAX. If the MS
datagrid won't work, do you have any suggestions for datagrids that would?
Also, if you know of a better alternative to MagicAJAX that would work with
Infragistics, that would be a great help as well.

Warmest Regards,
Scott
 
E

Elton Wang

Try

<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtBox_ID" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"Field_Name") %>' >
</ItemTemplate>
</asp:TemplateColumn>

to data bind text box in datagrid.

HTH

Scott McNair said:
Hi,

I've got a dataset that I'm generating through a webservice. I would like
to instantiate one of the tables in the set as a grid. Some of the
columns
in that grid should be editable via a textbox control, and I'd also like
to
have a checkbox to mark rows for delete, and some button controls to add
rows, update the data, or delete rows. Example:

DEL? FirstName LastName Birthdate ID (this is
hidden)
---- ---------- ----------- ----------- ---
[X] [Han ] [Solo ] [2/27/1973] 1
[ ] [Leia ] [Organa ] [4/13/1971] 2
[ ] [Luke ] [Skywalker] [4/13/1971] 3

[DELETE SELECTED] [ADD NEW ROW] [UPDATE TABLE]

My immediate solution was to create a datagrid and then create some
template columns to contain the data. My problem is that I can't figure
out how databound columns can be templates, nor how template columns can
be
databound. So I can either create columns with textboxes inside their
cells, or I can create columns with data in them, but not both.

I guess in a nutshell, my question is this: how do I create an editable,
bound datagrid? I've seen some examples of creating a class that inherits
ITemplate, but all the examples I've seen were in C# and although I can
comprehend C# on a basic level, large amounts of strange code can get me
lost. Plus, I'm not sure if those routes were the route I needed to take.

Please keep in mind the following:

* Since I'm pulling the data from a webservice, there's no way (that I
know
of at least) to create the datasource and bind it at runtime; instead I
have to establish the connection manually inside the codebehind.

* I must be able to actually mine the changes to the datagrid on the
server, by iterating thru the rows and then sending the new data back up
to
the webservice so that it can be updated at the data source. So the
textboxes should have function as well as form.

* I need the ability to do this thru AJAX (specifically thru the MagicAJAX
control at www.magicajax.net). The whole reason I'm having to research
this path is because my prior attempt (using an Infragistics grid) worked
perfectly EXCEPT for the fact that it would not work thru AJAX. If the MS
datagrid won't work, do you have any suggestions for datagrids that would?
Also, if you know of a better alternative to MagicAJAX that would work
with
Infragistics, that would be a great help as well.

Warmest Regards,
Scott
 
S

Scott McNair

Try

<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtBox_ID" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"Field_Name") %>' >
</ItemTemplate>
</asp:TemplateColumn>

to data bind text box in datagrid.

HTH

Great, that does the trick nicely. Thank you.

-Scott
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top