【问题标题】:How to auto generate web forms? [closed]如何自动生成网页表单? [关闭]
【发布时间】:2016-01-30 14:54:25
【问题描述】:

使用 Asp.net 4.0 和 Visual Studio 2010。 我有一个数据库和一个在其中插入新闻的表格,并且我制作了一个页面(WebForm)来将信息插入我的新闻表格。我有另一个页面,其中有一个网格视图,这个网格视图显示新闻表中的所有内容,现在我要做的是例如当管理员想要插入新闻时,然后将创建一个页面并且所有他插入的信息将显示在生成或自动创建的页面中。 同样在从新闻表显示的任何行旁边的网格视图中,我想显示一个超链接,该超链接会将页面重定向到具有所选行信息的页面(在我已经生成的页面中,我的意思是)。 有人可以帮忙吗?!

这是我的 gridview 代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDataSource1" Width="187px" CellPadding="4" 
EnableTheming="True" ForeColor="#333333" HorizontalAlign="Center" PageIndex="1" 
PageSize="5" ShowFooter="True" 
    >
    <AlternatingRowStyle BorderColor="White" BackColor="White" />
    <Columns>
        <asp:TemplateField>
            <HeaderTemplate>
                <div style="background-color: #FFFFFF">
                </div>
            </HeaderTemplate>
            <ItemTemplate>
                <div class="gridview" 

                    style="border-color: #FFFFFF; border-style: none; width: 924px; height: 141px; text-align: center; text-decoration: none;" 
                    align="right" dir="ltr">
                    <table class="auto-style1">
                        <tr>
                            <td class="style2">
                                <table class="auto-style1">
                                    <tr>
                                        <td>
                                            &nbsp;</td>
                                        <td style="text-align: left">
                                            <asp:Image ID="Image2" runat="server" Height="180px" 
                                                ImageUrl='<%# Eval("IMG") %>' Width="193px" BorderColor="#CCCCCC" 
                                                BorderStyle="Solid" />
                                        </td>
                                        <td>
                                            &nbsp;</td>
                                    </tr>
                                </table>
                            </td>
                            <td>
                                <table class="auto-style1">
                                    <tr>
                                        <td class="style9">
                                            <asp:Label ID="Label3" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("Fname") %>'></asp:Label>
                                        </td>
                                        <td class="style3">
                                            : نام</td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:Label ID="Label4" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("Lname") %>'></asp:Label>
                                        </td>
                                        <td class="style3">
                                            : نام خانوادگی</td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:Label ID="Label5" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("Major") %>'></asp:Label>
                                        </td>
                                        <td class="style8">
                                            : رشته تدریس</td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:Label ID="Label6" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("EnFname") %>'></asp:Label>
                                        </td>
                                        <td class="style3">
                                            : نام لاتین</td>
                                    </tr>
                                    <tr>
                                        <td class="style5">
                                            <asp:Label ID="Label7" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("EnLname") %>'></asp:Label>
                                        </td>
                                        <td class="style3">
                                            : نام خانوادگی با لاتین</td>
                                    </tr>
                                    <tr>
                                        <td class="style9">
                                            <asp:Label ID="Label8" runat="server" Font-Names="Microsoft Uighur" 
                                                Font-Size="X-Large" Text='<%# Eval("EnMajor") %>'></asp:Label>
                                        </td>
                                        <td class="style3">
                                            : رشته تدریس به لاتین</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
              <br />
              <br />
              <br />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <EmptyDataRowStyle BackColor="White" />
    <EmptyDataTemplate>
        <div style="height: 115px; width: 914px">
            No data to display<br />
            <br />
            <br />
            <br />
        </div>
    </EmptyDataTemplate>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <PagerTemplate>
        <div style="height: 131px; ">
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Fname") %>'></asp:Label>
            <br />
            <br />
            <asp:Label ID="Label2" runat="server" Text='<%# Eval("Lname") %>'></asp:Label>
            <br />
            <br />
        </div>
        <br />
        <br />
        <br />
        <br />
    </PagerTemplate>
    <RowStyle BorderColor="White" BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

【问题讨论】:

  • 表示在其他页面显示新闻详情。对吗?
  • 不,我的意思是当有人插入新闻时,会自动创建一个页面并将插入的数据显示在创建的页面中......
  • 意思是当你点击grid view row来重定向其他页面并在这个页面上显示选中的行数据?
  • 所以不需要生成动态页面。您可以使用查询字符串概念在单页中执行。
  • 那我该怎么做呢?

标签: c# html asp.net gridview webforms


【解决方案1】:
<a href='NewsDetail.aspx?newsId=<%# Eval("NewsId") %>'>    <asp:Image ID="Image2" runat="server" Height="180px"  ImageUrl='<%# Eval("IMG") %>' Width="193px" BorderColor="#CCCCCC"                                                 BorderStyle="Solid" /></a>

在 NewsDetail.aspx 页面上。

您可以像下面这样获取新闻ID:

int newsid= convert.ToInt32(Request.Querystring["newsId"]);

根据详情页的新闻id绑定数据后。在每一行点击你可以获得不同的新闻ID。

【讨论】:

  • 好的,我创建了一个网络表单,并在 page_load 中输入了以下代码:int newsid = Convert.ToInt32(Request.QueryString["NewsId"]); Label1.Text = newsid.ToString();
  • 但是我得到这个错误:输入字符串的格式不正确。
  • 在我的 gridview 项目模板中,我放了一个超链接,超链接的文本是新闻标题,当你点击它时,它会将你重定向到页面 NewsDetail.aspx 这是我的代码:` `
  • 我的问题已解决,谢谢
猜你喜欢
  • 2011-08-15
  • 2013-01-27
  • 2014-09-22
  • 1970-01-01
  • 2020-04-22
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多