你可在超链接中所链接的页面中判断传过来的参数值,如需要可有Response.Redirec("要去的页面").

解决方案 »

  1.   

    刚做的一个项目中:
    <asp:TemplateColumn HeaderText="政府公告标题" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center">
                                                                               
    <ItemTemplate>
                                                                                    <asp:HyperLink id=Title runat="server" Target=_blank text='<%# DataBinder.Eval(Container, "DataItem.Title") %>' NavigateUrl='<%# "GovAfficheShow.aspx?NodeCode="+DataBinder.Eval(Container, "DataItem.NodeCode") %>' style="width:200px;" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateColumn>
      

  2.   

    你是不是要使用C#提供的DataGrid控件。不好意思,如果想自动实现,我无法告诉你好办法,我试了试不行,可能需要你自己画个表格了。哎,Microsoft统一了stringGrid和DataGrid,但是仍然不够好用。你可以用点击事件来触发链接,这样就是麻烦一点。
      

  3.   

    现将超链一列做成模板列。
    然后在DataGrid的ItemCreated事件中这样写
    HyperLink h=e.Item.FindControl("HyperLink1");
    h.NavigateUrl="你需要的页面";
    e.target="_blank";
      

  4.   

    写错了应该在ItemDataBound事件中写。
      

  5.   

    希望我没理解错你的意思
    假定 你的datagrid的名字叫  dataGrid1 ,  dataGrid.Cell[6] 是超链接列在 dataGrid1的ItemDataBound事件里
    private void dataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {if(e.Item.ItemIndex > -1)
    {
    System.Web.UI.WebControls.HyperLink  hlc = (System.Web.UI.WebControls.HyperLink) e.Item.Cells[19].Controls[0];
    hlc.NavigateUrl ="你要链接的页面";


    }}
      

  6.   

    我的想法是:
    将超连接列换成模板列
    <TemplateItem>
      <Span style="cursor:hand" onclick='todo("<%#DataBinder.Eval(Container,"在此替换成你要判断的数据列")%>")'><%#DataBinder.Eval(Container,"在此替换成你要显示的数据列")%></Span>
    </TemplateItem>
    在aspx页面中加入
    <Script language=javascript>
     function todo(values)
    {
      if( values == '')
      //在此处理你想要的情况
    }
    </Script>
      

  7.   

    那当然要用DataGrid的模板来做咯,
    <%@ Page %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Data" %>
    <html>
      <body>
        <form method=post runat="server">
          <asp:DataGrid runat="server" ID="Datagrid1"
            DataKeyField="EmployeeID"
            OnEditCommand="Datagrid1_Edit"
            OnUpdateCommand="Datagrid1_Update"
            OnCancelCommand="Datagrid1_Cancel"
            OnDeleteCommand="Datagrid1_Delete"
            AutoGenerateColumns="False"
            Width="100%"
            HeaderStyle-Font-Size="10"
            HeaderStyle-Font-Bold="true"
            HeaderStyle-ForeColor="Red"
            HeaderStyle-BackColor="Yellow"
            HeaderStyle-BorderColor="Red"
            HeaderStyle-BorderWidth="5"
            FooterStyle-BorderColor="Red"
            FooterStyle-BorderWidth="5"    
            ItemStyle-BackColor="LightCyan"
            ItemStyle-ForeColor="DarkBlue"        
            AlternatingItemStyle-BackColor="LightYellow"
            AlternatingItemStyle-ForeColor="Maroon">
            <Columns>
              <asp:EditCommandColumn ItemStyle-Width="25px"
                EditText="<img border=0 alt='Edit record' src=Edit.gif>"
                CancelText="<img border=0 alt='Cancel changes' src=Cancel.gif>"
                UpdateText="<img border=0 alt='Accept changes'  src=OK.gif>"
              />
    <asp:ButtonColumn ItemStyle-Width="25px" ButtonType="LinkButton"
      Text="<img border=0 src=Delete.gif>" CommandName="delete"
    />
              <asp:BoundColumn HeaderText="ID" ItemStyle-Width="30px" DataField="EmployeeID" ReadOnly="true" />
              <asp:TemplateColumn HeaderText="Title" ItemStyle-Width="50px">
                <ItemTemplate>
                  <%# DataBinder.Eval(Container.DataItem, "TitleOfCourtesy") %>          
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:DropDownList runat="server" ID="EditTitle" DataSource='<%# TitlesOfCourtesy %>'
                    SelectedIndex='<%# GetSelectedTitle(DataBinder.Eval(Container.DataItem, "TitleOfCourtesy")) %>' />
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="Name">
                <ItemTemplate>
                  <b><%# DataBinder.Eval(Container.DataItem, "LastName") %></b>,
                  <%# DataBinder.Eval(Container.DataItem, "FirstName") %>          
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox runat="server" ID="EditLastName" Text='<%# DataBinder.Eval(Container.DataItem, "LastName") %>' />
                  <asp:TextBox runat="server" ID="EditFirstName" Text='<%# DataBinder.Eval(Container.DataItem, "FirstName") %>' />
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:BoundColumn HeaderText="City" ItemStyle-Width="150px" DataField="City" />
              <asp:TemplateColumn HeaderText="USA?" ItemStyle-Width="35px" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                  <asp:CheckBox runat="server" Enabled="false"
                    Checked='<%# DataBinder.Eval(Container.DataItem, "Country").ToString() == "USA" %>' />
                </ItemTemplate>
              </asp:TemplateColumn>
            </Columns>
          </asp:DataGrid>
        </form>
      </body>
    </html><script runat="server" language="C#">
      public string[] TitlesOfCourtesy 
      {
        get {
          return new string[4]{"Mr.", "Dr.", "Ms.", "Mrs."};
        }
      }
      
      int GetSelectedTitle(object title)
      {
        return Array.IndexOf(TitlesOfCourtesy, title.ToString());
      }
      
      void Page_Load()
      {
        if (!Page.IsPostBack)
          BindGrid();
      }
      
      void BindGrid()
      {
        // create the command and the connection
        string connString = "server=(local);database=Northwind;uid=sa;pwd=;";
        string sql = @"SELECT * FROM Employees";
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(sql, conn);
          
        // open the connection and get the Reader
        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
               
        // bind the reader to the DataList
        Datagrid1.DataSource = reader;
        Datagrid1.DataBind();
          
        // close the reader and the connection
        reader.Close();
        conn.Close();
      }
      
      void Datagrid1_Edit(Object sender, DataGridCommandEventArgs e)
      {
        Datagrid1.EditItemIndex = (int)e.Item.ItemIndex;
        BindGrid();
      }
      
      void Datagrid1_Cancel(Object sender, DataGridCommandEventArgs e)
      {
        Datagrid1.EditItemIndex = -1;
        BindGrid();
      }  void Datagrid1_Update(Object sender, DataGridCommandEventArgs e)
      {
        // get the ID of the record to update
        int empID = (int)Datagrid1.DataKeys[e.Item.ItemIndex];
        
        // get the references to the edit controls
        DropDownList title = (DropDownList)e.Item.FindControl("EditTitle");
        TextBox lastName = (TextBox)e.Item.FindControl("EditLastName");
        TextBox firstName = (TextBox)e.Item.FindControl("EditFirstName");
        TextBox city = (TextBox)e.Item.Cells[5].Controls[0];
        
        // create the connection and the UPDATE command
        string connString = "server=(local);database=Northwind;uid=sa;pwd=;";
        string sql = @"UPDATE Employees SET TitleOfCourtesy = @TitleOfCourtesy, 
          LastName = @LastName, FirstName = @FirstName, City = @City WHERE EmployeeID = @EmployeeID";
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(sql, conn);
        
    // create the required parameters
        cmd.Parameters.Add(new SqlParameter("@TitleOfCourtesy", SqlDbType.NVarChar, 25));
    cmd.Parameters["@TitleOfCourtesy"].Value = title.SelectedItem.Text.Trim();
        cmd.Parameters.Add(new SqlParameter("@LastName", SqlDbType.NVarChar, 20));
    cmd.Parameters["@LastName"].Value = lastName.Text.Trim();
    cmd.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.NVarChar, 10));
    cmd.Parameters["@FirstName"].Value = firstName.Text.Trim();
    cmd.Parameters.Add(new SqlParameter("@City", SqlDbType.NVarChar, 15));
    cmd.Parameters["@City"].Value = city.Text.Trim();
    cmd.Parameters.Add(new SqlParameter("@EmployeeID", SqlDbType.Int, 4));
    cmd.Parameters["@EmployeeID"].Value = empID;

        // execute the command
        cmd.Connection.Open();
        try {
          cmd.ExecuteNonQuery();
        }
        catch (SqlException) {
          // handle exception... 
        }
        finally { 
          cmd.Connection.Close();
        }
        
        // stop the editing and rebind the grid
        Datagrid1.EditItemIndex = -1;
        BindGrid();
      }
      
      void Datagrid1_Delete(Object sender, DataGridCommandEventArgs e)
      {
        // get the ID of the record to update
        int empID = (int)Datagrid1.DataKeys[e.Item.ItemIndex];
           
        // create the connection and the DELETE command
        string connString = "server=(local);database=Northwind;uid=sa;pwd=;";
        string sql = @"DELETE FROM Employees WHERE EmployeeID = " + empID.ToString();
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(sql, conn);
        
        // execute the command
        cmd.Connection.Open();
        try {
          cmd.ExecuteNonQuery();
        }
        catch (SqlException) {
          // handle exception... 
        }
        finally { 
          cmd.Connection.Close();
        }
        
        // rebind the grid
        Datagrid1.EditItemIndex = -1;
        BindGrid();
      }
    </script>
    以上是类似的模板代码,你可以改一些,比如把里面的<asp:DropDownList>控件改成
    <asp:LinkButton>把URL动态的设为'<% 服务器端的变量 %>'.
    OK了.
      

  8.   

    1.在绑定期间做 修改DataGrid的改行Text为<a>...</a>
    2.在显示完毕做