如何使用JavaScript或代码将HTML表与数据库绑定

时间:2022-08-25 23:23:45

I want to create one html table. that table contains 2 columns like teamName, TeamMember.

我想创建一个html表。该表包含2个列,如teamName,TeamMember。

TeamName columns like label and Teammember columns like checkboxlist.

TeamName列,如label和Teammember列,如checkboxlist。

How to create and bind?

如何创建和绑定?

In aspx page my code like

在aspx页面我的代码就像

<table id="table1" border="1" align="center">
            <tr>
                <th>
                    TeamName
                </th>
                <th>
                    TeamMember
               </th>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbl1" runat="server"></asp:Label>
                </td>
                <td>
                    <asp:CheckBoxList ID="cblbind" runat="server">
                   </asp:CheckBoxList>
                </td>
            </tr>
        </table>

How to I bind these table?

如何绑定这些表?

In database my procedure:

在数据库我的程序:

alter procedure TeamBindingProc

@teamid as int

as

begin

select Teamid,TeamName from Team

    select UserId,TeamID,(select Nickname From [user] where [user].userid=TeamDetails.Userid)as Nickname from TeamDetails where Teamid=@teamid

end

2 个解决方案

#1


0  

Maybe you should have a look at the ListView control. You can use it like this

也许你应该看一下ListView控件。你可以像这样使用它

    <asp:ListView runat="server">
        <LayoutTemplate>
            <table id="table1" border="1" align="center">
                <tr>
                    <th>TeamName
                    </th>
                    <th>TeamMember
                    </th>
                </tr>
                <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="lbl1" Text='<%# Eval("ColumnNameOfYourTable") %>' runat="server"></asp:Label>
                </td>
                <td>
                    <asp:CheckBoxList ID="cblbind" runat="server">
                    </asp:CheckBoxList>
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>

The datasource for the ListView can then be a SqlDataSource where you can use your sql query.

然后,ListView的数据源可以是SqlDataSource,您可以在其中使用sql查询。

#2


0  

First of all you execute the stored procedure and fill it into the Dataset....and then you declare <table id='table1' runat='server'> and then on page load construct the HTML required for it using a string builder like this

首先,执行存储过程并将其填入数据集....然后声明

然后在页面上使用字符串构建器构造它所需的HTML喜欢这个
stingBuilder.Append("<tbody>");
stingBuilder.Append("<tr>");
stingBuilder.Append("<th>First Name</th>");
stingBuilder.Append("<th>Last Name</th>");

///more Html here as required by you

stingBuilder.Append("</tbody>");

and then at last append the stringbuilder to the table using

然后最后将stringbuilder附加到表中使用

table1.innerHtml=stringBuilder.ToString();

also for dataBinding with JavaScript you can use AJAX call method, and you can return the same HTML through and in the success function. You can bind it to the table using the Id of it.

对于使用JavaScript的dataBinding,您可以使用AJAX调用方法,并且可以通过成功函数返回相同的HTML。您可以使用它的ID将其绑定到表。

#1


0  

Maybe you should have a look at the ListView control. You can use it like this

也许你应该看一下ListView控件。你可以像这样使用它

    <asp:ListView runat="server">
        <LayoutTemplate>
            <table id="table1" border="1" align="center">
                <tr>
                    <th>TeamName
                    </th>
                    <th>TeamMember
                    </th>
                </tr>
                <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="lbl1" Text='<%# Eval("ColumnNameOfYourTable") %>' runat="server"></asp:Label>
                </td>
                <td>
                    <asp:CheckBoxList ID="cblbind" runat="server">
                    </asp:CheckBoxList>
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>

The datasource for the ListView can then be a SqlDataSource where you can use your sql query.

然后,ListView的数据源可以是SqlDataSource,您可以在其中使用sql查询。

#2


0  

First of all you execute the stored procedure and fill it into the Dataset....and then you declare <table id='table1' runat='server'> and then on page load construct the HTML required for it using a string builder like this

首先,执行存储过程并将其填入数据集....然后声明

然后在页面上使用字符串构建器构造它所需的HTML喜欢这个
stingBuilder.Append("<tbody>");
stingBuilder.Append("<tr>");
stingBuilder.Append("<th>First Name</th>");
stingBuilder.Append("<th>Last Name</th>");

///more Html here as required by you

stingBuilder.Append("</tbody>");

and then at last append the stringbuilder to the table using

然后最后将stringbuilder附加到表中使用

table1.innerHtml=stringBuilder.ToString();

also for dataBinding with JavaScript you can use AJAX call method, and you can return the same HTML through and in the success function. You can bind it to the table using the Id of it.

对于使用JavaScript的dataBinding,您可以使用AJAX调用方法,并且可以通过成功函数返回相同的HTML。您可以使用它的ID将其绑定到表。