2015-08-13 29 views
0
<asp:TemplateField HeaderText="ID" SortExpression="CareerFormID"> 
           <ItemTemplate> 
            <asp:Label ID="CareerFormID" runat="server" Text='<%#Eval("CareerFormID")%>' /> 
           </ItemTemplate> 
          </asp:TemplateField> 
<asp:BoundField HeaderText="Checked" DataField="checked" /> 

<asp:ButtonField Text="Edit" CommandName="Select" ButtonType="Link" /> 

    protected void OnSelectedIndexChanged(object sender, EventArgs e) 
{ 
    string idtemp = (GridView1.SelectedRow.FindControl("CareerFormID") as Label).Text; 
    Session["CompanyFormID"] = idtemp; 
    Response.Redirect("Management_Edit.aspx"); 
    //Response.Write(Session["CompanyFormID"]); 
} 

當DataField =「checked」爲1時,我想更改ButtonField text =「Modify」,我該怎麼做?如何更改asp.net中的ButtonField文本

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 

     if (e.Row.Cells[4].Text == "1") 
     { 
      e.Row.Cells[4].Text = "Yes"; 
      e.Row.Cells[4].ForeColor = System.Drawing.Color.Green; 
      e.Row.Cells[6].Text = "Modify"; 

     } 
     else if (e.Row.Cells[4].Text == "0") 
     { 
      e.Row.Cells[4].Text = "No"; 
      e.Row.Cells[4].ForeColor = System.Drawing.Color.Red; 
     } 

    } 

} 

但這不起作用,單元格[6]文本被更改,但鏈接被取消。

對於這樣的例子,當我更改文本

http://i.imgur.com/CN5snv6.jpg

回答

0

使事件處理程序,數據字段=「選中」鏈接不能工作爲1(我也不在你的代碼中找到它,如何做到1)並做到這一點

//begin of event handler 
//check datafield="checked" is 1, I still don't get it this one 
ButtonField.Text="Modify" 
//end of event handler 
相關問題