【问题标题】:hyperlink in gridview with procedure带有过程的gridview中的超链接
【发布时间】:2013-12-03 13:57:33
【问题描述】:

我有这个页面 buscli.aspx

现在工作正常,griview 的来源是一个存储过程

string valorC = "%" + TextBox1.Text + "%"; numo = DropDownList1.SelectedValue;
        switch (numo)
        { 
            case "Nome":  num3 = 1;  break;
            case "Endereço": num3 = 2; break ;
            case "Telefone": num3 = 3 ; break;
            case "Pedido": num3 = 4; break ;
        }

        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "cazacliente2";
        SqlParameter valor = new SqlParameter("@vbusca", SqlDbType.NVarChar);
        SqlParameter num = new SqlParameter("@bo",SqlDbType.Int );
        valor.Value = valorC   ; num.Value = num3 ; 
        cmd.Parameters.Add(valor); cmd.Parameters.Add(num);
        cmd.Connection = conex1;
        try
        {
            GridView1.EmptyDataText = "Nao se" + numo.ToString()  +"econtraron registros";
            GridView1.DataSource = cmd.ExecuteReader();
            GridView1.DataBind();

        }
        catch (Exception ex)
        { throw ex; }
        finally
        {
            conex1.Close();
            conex1.Dispose();
        }

但现在我需要在超链接中转换 pedido 列,我看到了很多 youtube 示例,但都是数据集,我尝试了任何带有超链接字段的结果。

【问题讨论】:

    标签: c# asp.net gridview hyperlink


    【解决方案1】:

    您需要使用 Gridview 的 RowDataBound 事件来操作数据的呈现方式。以下是来自 MSDN http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound(v=vs.110).aspx的示例

    void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
    
        if(e.Row.RowType == DataControlRowType.DataRow)
        {
          // Display the company name in italics.
          e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
    
        }
    
      }
    

    【讨论】:

      【解决方案2】:

      您可以简单地在 gridview 中添加一个模板列并添加一个锚标记。请注意,您应该使用 http:// 使链接正常工作。下面是一个示例。这里的 ColumnName 和 ColumnValue 是来自 DataTable/List/Collection 作为数据源的列。

      <asp:templatefield>
      <itemtemplate>
        <a href='<%string.Format("http://www.yourlink.com/page.aspx?id={0}",
        Eval("ColumnName"))%>' runat="server">Eval("ColumnValue")</a>
      </itemtemplate>
      </asp:templatefield>
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多