469,889 Members | 1,268 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

binding dt to txt

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
Mar 29 '07 #1
2 1269

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.

Mar 30 '07 #2
thank you very much for the help.
rod.

"Parvathy Padmanabhan" wrote:
>
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.
Mar 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.