2012-03-14 35 views
1

我有GridView模板Column.Inside模板列中我有asp:hiddenfield。我結合使用method.When我試圖訪問hiddenfi的價值不入店的eval()的值,而知名度假 ASPXGridView模板列的隱藏字段值始終爲0,而​​可見性爲假

<asp:TemplateField HeaderText="Select" Visible="false"> 
     <ItemTemplate> 
      <asp:HiddenField ID="hdnMasterId" runat="server" 
       Value='<%# DataBinder.Eval(Container.DataItem, "Master_Id") %>' /> 
      <asp:CheckBox ID="chkDelete" runat="server" /> 
     </ItemTemplate> 
     <ItemStyle Width="4%" HorizontalAlign="Center"></ItemStyle> 
      <HeaderStyle HorizontalAlign="Center" /> 
    </asp:TemplateField> 

後面的代碼

protected void gdvList_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    int intIndex = Convert.ToInt32(e.CommandArgument); 
    GridViewRow row = gdvList.Rows[intIndex]; 
    HiddenField hdn = (HiddenField)row.FindControl("hdnMasterId"); 
} 
+0

你可以添加你的代碼嗎? – 2012-03-14 06:10:37

+0

@ Mansoor Gee: - 當我試圖訪問hiddenfield值時,它始終爲空。 – 2012-03-14 11:07:31

回答

1

如果它贏得了列設置可見=「假」不生成任何HTML,因此不會有隱藏的控制。您需要將隱藏的字段放在其他位置,或者使用css/style隱藏該列。

+0

: - 感謝您的回覆...是否可以通過使用asp:Label控件獲取相同內容? – 2012-03-14 07:12:51

+0

你是什麼意思?標籤將轉換爲div標籤,不會發回任何內容。 – 2012-03-14 09:54:43

+0

我在templete列中添加了一個標籤,它的可見性爲false,現在將文本與row_command中的Master_Id.Now綁定,我正在獲取文本值。 – 2012-03-14 11:16:15

0

你可以嘗試爲:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 
{ 

string strValue = ((HiddenField)GridView1.SelectedRow.Cells[cellindex].FindControl("HiddenFieldID")).Value; 
}