none
内容页什么时候修改母版页控件属性 RRS feed

  • 问题

  • 母版页的image控件是根据数据库循环添加的,现在在内容页有个text控件。现在我想点击图片将相应的内容显示在text里,该怎么做啊(主要是怎么样添加img的onclick事件把内容页的text的ID给它),请大家不吝赐教!!
    2009年12月12日 9:42

答案

  • <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
    <!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>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body  >
        <form id="form1" runat="server">
        <div  >
            <asp:DataList ID="DataList1" runat="server" DataKeyField="id" 
                DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    id:
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    names:
                    <asp:Label ID="namesLabel" runat="server" Text='<%# Eval("names") %>' />
                    <br />
                    m:
                    <asp:Label ID="mLabel" runat="server" Text='<%# Eval("m") %>' />
                    <br />
                    b:
                    <asp:Label ID="bLabel" runat="server" Text='<%# Eval("b") %>' />
                    <asp:ImageButton ID="ImageButton1" runat="server" 
                        AlternateText='<%# Eval("id") %>' onclick="ImageButton1_Click" />
                    <br />
                    <br />
                </ItemTemplate>
            </asp:DataList>    
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:linqdataConnectionString %>" 
                SelectCommand="SELECT * FROM [linqname]"></asp:SqlDataSource>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>
            protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
            {
                Label l = this.ContentPlaceHolder1.FindControl("Label1") as Label;
                l.Text = (sender as ImageButton).AlternateText;
            }
    内容页

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </asp:Content>
    • 已标记为答案 海格 2009年12月12日 13:14
    2009年12月12日 10:25

全部回复

  • <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
    <!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>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body  >
        <form id="form1" runat="server">
        <div  >
            <asp:DataList ID="DataList1" runat="server" DataKeyField="id" 
                DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    id:
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    names:
                    <asp:Label ID="namesLabel" runat="server" Text='<%# Eval("names") %>' />
                    <br />
                    m:
                    <asp:Label ID="mLabel" runat="server" Text='<%# Eval("m") %>' />
                    <br />
                    b:
                    <asp:Label ID="bLabel" runat="server" Text='<%# Eval("b") %>' />
                    <asp:ImageButton ID="ImageButton1" runat="server" 
                        AlternateText='<%# Eval("id") %>' onclick="ImageButton1_Click" />
                    <br />
                    <br />
                </ItemTemplate>
            </asp:DataList>    
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:linqdataConnectionString %>" 
                SelectCommand="SELECT * FROM [linqname]"></asp:SqlDataSource>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
         </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>
            protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
            {
                Label l = this.ContentPlaceHolder1.FindControl("Label1") as Label;
                l.Text = (sender as ImageButton).AlternateText;
            }
    内容页

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </asp:Content>
    • 已标记为答案 海格 2009年12月12日 13:14
    2009年12月12日 10:25
  • 非常谢谢!致敬!

    2009年12月12日 13:14