binding dt to txt

G

Guest

hey all,
i have an incoming datatable in my web page and i'd like to bind one of the
fields to a textbox. can someone please show me how to do this?

thanks,
rodchar
 
G

Guest

Hi,

When you say binding an incoming datatable to a textbox, do you mean
binding a specific row's column value of the datatable?

Incase you need to bind the textbox to a specific row's cell value, then
probably you could try this option:

<input type="text" id="txtcon" value="<%= dt.Rows[0][0]%>" />

But then, if you need an asp:textbox to be bound through your html code, in
that case, the asp:textbox needs to be supported with another hidden input
textbox, followed by a script.

<input type="text" id="txtcon"
style="DISPLAY:none;"
value="<%= dt.Rows[0][0]%>" />
<asp:TextBox ID="txtContent" runat="Server"></asp:TextBox>

<script type="text/javascript">
document.getElementById("txtContent").value =
document.getElementById("txtcon").value
</script>

This code will be useful if you specifically want to bind in the html source
itself.

But if that is not mandatory, the same can be achived by simply assigning
the text property of the asp:textbox to the particular field value of the
datatable.

Also, the textbox can be bound to only 1 cell value of the entire datatable
at a time.

I hope this helps.
-Parvathy.
 

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,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top