2012-06-06 152 views
0

我想從GridView的單元格的值,但空字符串。我是實施 在單選按鈕列表的SelectedIndexChanged事件的所有代碼。我的代碼。但問題是通過迭代的GridView
和接入小區stll remaining.I使用了三個ItemTemplate中,每個
有一個elemnt使每個元素獲得自己的coulmn 的.aspx獲取單元格值

 <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" > 

     <Columns> 

 <asp:Label ID="Label2" runat="server" Text='<%# Eval("qno") %>'> 

    </asp:Label> 
     </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField> 
    <ItemTemplate> 
      <asp:Label ID="Label3" runat="server" Text='<%# Eval("description") 

%>'>

</ItemTemplate> 
    </asp:TemplateField> 

<asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal" 
    runat="server" OnSelectedIndexChanged="changed" AutoPostBack="true" > 


    <asp:ListItem Value="agree" Selected="True" > 

    </asp:ListItem> 
     <asp:ListItem 
     Value="disagree"> 

    </asp:ListItem> 
     <asp:ListItem Value="strongagree"> 

    </asp:ListItem> 
     <asp:ListItem Value="strondisagree"> 

    </asp:ListItem> 
     </asp:RadioButtonList> 

後面
 </Columns> 

    </asp:GridView> 

<asp:Label ID="Labe11" runat="server" ></asp:Label> 

代碼: 公共無效改變(對象發件人,EventArgs的) {

 for(int i=0;i<GridView2.Rows.Count;i++) 
     { 
      string labtext; 
      RadioButtonList list = 
    GridView2.Rows[i].Cells[2].FindControl("RadioButtonList1") as RadioButtonList; 
      labtext= GridView2.Rows[i].Cells[0].Text; 


      Label1.Text = labtext; 


     } 



      } 

回答

3

我想你正在尋找gridview的RowUpdating事件。下面的代碼來自我在幾年前工作過的一個項目,我必須從gridview中的組合框中獲取值。希望這會讓你更接近解決方案。

protected void gvReconciliation_RowUpdating(object sender, GridViewUpdateEventArgs e) 
    { 
     DropDownList dropDownListUser = gvReconciliation.Rows[e.RowIndex].FindControl("ddlSourceEdit") as DropDownList; 
     e.NewValues["source"] = dropDownListUser.SelectedItem.Text; 
    } 

我對照綁定到一個對象數據源所以這就是爲什麼你看到在那裏e.NewValues["source"]。 「Source」是我的ObjectDataSource中綁定的列名。

+0

但我想要得到label2的文本 – user1405508

+0

你應該能夠將label2及其類型添加到上面的代碼中,或者非常接近它並獲得你所需要的。如果你需要特定的代碼,如果你需要那麼多的幫助,我可以寫給你。 –