如何在ASP中设置GridView SelectButton的URL?

时间:2016-04-24 02:55:19

标签: asp.net

我有一个GridView,它显示了一个数据库结果表。我将ShowSelectButton设置为true,但链接总是将我带回到GridView所在的页面。如何更改SelectButton的URL以表示UpdateItem.aspx?id = ???哪里???等于db行的ID?

<asp:SqlDataSource ID="GetStudents" runat="server" ConnectionString="<%$ ConnectionStrings:dbConn %>" SelectCommand="dbo.GetStudents" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
        <asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:CommandField ShowSelectButton="true" />
                <asp:BoundField DataField="studentId" HeaderText="ID" />
                <asp:BoundField DataField="firstName" HeaderText="First Name" />
                <asp:BoundField DataField="lastName" HeaderText="Last Name" />

2 个答案:

答案 0 :(得分:0)

<body>
    <div class="box">
        <div class="box1">box1
        </div>
        <div class="box2">box2
        </div>
        <div class="box4">box4
        </div>
        <div class="box5">box5
        </div>
        <div class="box3">box3
        </div>
        <div class="box6">box6
        </div>
    </div>
    </body>

<asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="StudentId" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">

也许你可以考虑尝试上面的一些,看看是否有帮助。

答案 1 :(得分:0)

您可以使用HyperLink或LinkBut​​ton将CommandField替换为TemplateField

<asp:TemplateField>
    <ItemTemplate>
        <asp:HyperLink runat="server" NavigateUrl='<%# "~/UpdateItem.aspx?id=" + Eval("ID") %>' Text="Select" />
    </ItemTemplate>
</asp:TemplateField>