c#
  • asp.net
  • gridview
  • 2014-09-02 59 views 0 likes 
    0

    我有一些column.First列一個GridView是一個模板字段:在ASP.NET中的GridView上選擇全行?

    ... 
    <asp:TemplateField HeaderText="id"> 
         <ItemTemplate> 
          <asp:HyperLink ID="HyperLink1" runat="server" 
             NavigateUrl='<%# "~/mail/showMail.aspx?q="+Eval("id") %>'>Select</asp:HyperLink> 
          </ItemTemplate> 
    </asp:TemplateField> 
    ... 
    

    我想使用全行選擇,而不是這上面的TemplateField。我用這個代碼:

    protected void grdList_RowCreated(object sender, GridViewRowEventArgs e) 
    { 
         if (e.Row.RowType == DataControlRowType.DataRow) 
         { 
          e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';"; 
          e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; 
          e.Row.ToolTip = "Click to select row"; 
          e.Row.Attributes["onclick"] = 
           this.Page.ClientScript. 
           GetPostBackClientHyperlink(this.grdList, "Select$" + e.Row.RowIndex); 
         } 
    } 
    

    但是不行。

    如何使用超鏈接,而不是 「選擇$」,就像這樣:

    ClientScript. 
           GetPostBackClientHyperlink(this.grdList, "~/mail/showMail.aspx?q=Eval(\"id\")"); 
    

    回答

    0

    找到了解決辦法:

    我用一個BoundField代替模板字段是這樣的:

    <asp:BoundField DataField="id" HeaderText="id" /> 
    

    並使用此事件:

    protected void grdList_SelectedIndexChanged(object sender, EventArgs e) 
    { 
         GridViewRow SelectedRow = grdList.SelectedRow; 
         string id = SelectedRow.Cells[0].Text; 
         Response.Redirect("~/Mail/ShowMail.aspx?q=" + id); 
    } 
    
    protected void grdList_RowCreated(object sender, GridViewRowEventArgs e) 
    { 
        if (e.Row.RowType == DataControlRowType.DataRow) 
        { 
         e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';"; 
         e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; 
         e.Row.ToolTip = "Click to select row"; 
         e.Row.Attributes["onclick"] = 
          this.Page.ClientScript. 
          GetPostBackClientHyperlink(this.grdList, "Select$" + e.Row.RowIndex); 
        } 
    } 
    
    +0

    全行選擇怎麼樣? – Hassan 2014-09-02 04:46:02

    相關問題