2012-06-06 44 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及其类型添加到上面的代码中,或者非常接近它并获得你所需要的。如果你需要特定的代码,如果你需要那么多的帮助,我可以写给你。 –