我想使用模板数据字段而不是boundfield数据字段,如何实现? [英] I want to use template datafield instead of boundfield datafield, how can it be achieved?

查看:65
本文介绍了我想使用模板数据字段而不是boundfield数据字段,如何实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Page2.aspx.cs" Inherits="WebApplication1.Page2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 270px;
        }
        .style3
        {
            width: 270px;
            text-align: right;
        }
        .style4
        {
            width: 223px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <script language="javascript" type="text/javascript">
//        function welcome() {
//            var name = document.getElementById("TextBoxName").value;
//            alert('Welcome to J Script :' + name);
//        }
    </script>
    <table class="style1">
        <tr>
            <td class="style3">
                Name :</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                City:</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxCity" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                State :</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxState" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                Phone no.</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxPhone" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                Salary :</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxSalary" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                Age:</td>
            <td class="style4">
                <asp:TextBox ID="TextBoxAge" runat="server" style="margin-bottom: 0px"

                    MaxLength="2"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3">
                Gender :</td>
            <td class="style4">
                <asp:DropDownList ID="DropDownListGender" runat="server" Height="28px"

                    Width="125px">
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>Male</asp:ListItem>
                    <asp:ListItem>Female</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td class="style4">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td class="style4">
                <asp:Button ID="ButtonSubmit" runat="server"

                   onclick="ButtonSubmit_Click"

                    Text="Submit" Width="129px" style="height: 26px" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        </table>
    <asp:Label ID="Error_Label" runat="server"></asp:Label>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

        DataSourceID="SqlDataSource" AllowPaging="True" AllowSorting="True" OnSorting="GridView1_Sorting"

        Width="467px" onselectedindexchanged="GridView1_SelectedIndexChanged1">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
            <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
            <asp:BoundField DataField="Salary" HeaderText="Salary"

                SortExpression="Salary" />
            <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
            <asp:BoundField DataField="Gender" HeaderText="Gender"

                SortExpression="Gender" />
        </Columns>

        <EmptyDataTemplate>
            <asp:Label ID="Name" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
            <asp:Label ID="City" runat="server" Text='<%# Eval("City") %>'></asp:Label>
            <asp:Label ID="State" runat="server" Text='<%# Eval("State") %>'></asp:Label>
            <asp:Label ID="Phone" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>
            <asp:Label ID="Salary" runat="server" Text='<%# Eval("Salary") %>'></asp:Label>
            <asp:Label ID="Age" runat="server" Text='<%# Eval("Age") %>'></asp:Label>
            <asp:Label ID="Gender" runat="server" Text="Label"></asp:Label>
        </EmptyDataTemplate>

    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource" runat="server"

        ConnectionString="<%$ ConnectionStrings:newConnectionString %>"

        SelectCommand="SELECT * FROM [page2]"></asp:SqlDataSource>
    </form>
</body>
</html>

推荐答案

ConnectionStrings:newConnectionString %>\"

SelectCommand=\"SELECT * FROM [page2]\"> </asp:SqlDataSource>
</form>
</body>
</html>
ConnectionStrings:newConnectionString %>" SelectCommand="SELECT * FROM [page2]"></asp:SqlDataSource> </form> </body> </html>


Refer this link : Using TemplateFields in the GridView Control (C#)
Refer this link : Using TemplateFields in the GridView Control (C#)


这篇关于我想使用模板数据字段而不是boundfield数据字段,如何实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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