将HTML表数据填充到表单 [英] Populating HTML table data to a form

查看:215
本文介绍了将HTML表数据填充到表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have the table in the below format.







FirstName姓氏

Jill Smith

Eve Jackson



此外,我还有表格更新名字&姓。这是表格代码。






FirstName Last Name
Jill Smith
Eve Jackson

Also i have Form for updating the firstname & lastname. This is the form code.

<!DOCTYPE html>
<html>
<body>

<form border="1">
  <tr>
     <td><label >FirtsName</label></td>
     <td><input type="text" id="firstname" class="medium"></td>
    </tr>
  <tr>
   <td><label >LastName</label></td>
   <td><input type="text" id="lastname" class="medium"></td>
   </tr>

</form>

</body>
</html>










How to send the table data to a form using jquery or javascript. Any help will be much appreciated!

Thanks & regards Karthick

推荐答案

您好Karthick,

您需要使用SqlDataReader对象来读取数据库中的数据。您还可以使用reader对象将表值分配给控件。

请参阅链接:

使用DataReader检索数据 [ ^ ]。

试试这个:

Hi Karthick,
You need to use SqlDataReader Object to read the data from database. And also you can assign the value of your table to a control using reader object.
See the link:
Retrieving Data Using the DataReader[^].
Try this:
SqlConnection con = new SqlConnection("YourConnectionStringHere");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Table1", con);
SqlDataReader sdr = cmd.ExecuteReader();
while(sdr.Read())
{
    TextBox1.Text = Convert.ToString(sdr["FirstName"]);
    TextBox2.Text = Convert.ToString(sdr["LastName"]);
}
//Releasing the objects
sdr.Dispose();
cmd.Dispose();
con.Close();





--Amit



--Amit


这篇关于将HTML表数据填充到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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