尝试在其列中超链接gridview项

时间:2018-01-15 10:58:35

标签: c# asp.net gridview hyperlink ado.net

我有一个表单,其中数据在gridview中动态添加我想让其中一个字段项超链接并重定向到下一页。但是没有获得超链接。任何想法都会因为它的超链接而受到赞赏。

<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" Font-Names="Arial" style="display: none"
    Font-Size="10pt" RowStyle-BackColor="#A1DCF2" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor = "White">
                <Columns>
                     <asp:TemplateField HeaderText = "TDC_NO" ItemStyle-Width="150px">
            <ItemTemplate>
                <asp:HyperLink runat="server" NavigateUrl='<%# Eval("TDC_NO", "~/Uncoated_Wire.aspx?Id={0}") %>'
                    Text='<%# Eval("TDC_NO") %>' />
            </ItemTemplate>
        </asp:TemplateField>
                 <%--   <asp:HyperLinkField ItemStyle-Width="150px" DataTextField="TDC_NO" DataNavigateUrlFields="TDC_NO" DataNavigateUrlFormatString="~/Uncoated_Wire.aspx?TDC_NO={0}"
            HeaderText="TDC_NO"/>--%>                 
                    <%--<asp:BoundField ItemStyle-Width="150px" DataField="TDC_NO" HeaderText="TDC_NO" />--%>
                    <asp:BoundField ItemStyle-Width="150px" DataField="REVISION" HeaderText="REVISION" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="REVISION_DATE" HeaderText="REVISION_DATE" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="P_GROUP" HeaderText="P_GROUP" />                       
                </Columns>
            </asp:GridView>

我尝试了两种方式使用ItemTemplateField并使用上面的HuperlinkField,但gridview中的项目绑定没有超链接。 Gridview填充aspx中的代码

<%--GridView Populate--%> 
    <script type="text/javascript">
        $(function () {
            $("#THistory").click(function (event) {               
                event.preventDefault();
                $("#pdfFormInsideL1").hide();
                document.getElementById('<%=gvCustomers.ClientID%>').style.display = 'block';
                //$("#gvCustomers").show();
                $("#gvCustomers").attr("visibility", "visible");
                $.ajax({
                    type: "POST",
                    url: "TDC.aspx/GetCustomers",
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert(response.d);
                    },
                    error: function (response) {
                        alert(response.d);
                    }
                });
            });
            function OnSuccess(response) {
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var customers = xml.find("Table");
                var row = $("[id*=gvCustomers] tr:last-child").clone(true);
                $("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
                $.each(customers, function () {
                    var customer = $(this);
                    $("td", row).eq(0).html($(this).find("TDC_NO").text());
                    $("td", row).eq(1).html($(this).find("REVISION").text());
                    $("td", row).eq(2).html($(this).find("REVISION_DATE").text());
                    $("td", row).eq(3).html($(this).find("P_GROUP").text());
                    $("[id*=gvCustomers]").append(row);
                    row = $("[id*=gvCustomers] tr:last-child").clone(true);
                });
            }
        });
        </script>
     <%--GridView Populate--%>

C#代码

[WebMethod]
    public static string GetCustomers()
    {
        string query = "SELECT TDC_NO,REVISION,REVISION_DATE, P_GROUP from tdc_product1 ";
        OracleCommand cmd = new OracleCommand(query);
        return GetData(cmd).GetXml();
    }
    private static DataSet GetData(OracleCommand cmd)
    {
        string strConnString = ConfigurationManager.ConnectionStrings["conndbprodnew"].ConnectionString;
        using (OracleConnection con = new OracleConnection(strConnString))
        {
            using (OracleDataAdapter sda = new OracleDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataSet ds = new DataSet())
                {
                    sda.Fill(ds);
                    return ds;

                }
            }
        }
    }

0 个答案:

没有答案