如何查找一个Panel中的一个GridView中的ItemTemplate项中某一个控件(如:Label)的值?

解决方案 »

  1.   

     Label lbl= ((Label )GridView.Rows[e.RowIndex].FindControl("Label")).Text;
      

  2.   

    错误 47 “System.Web.UI.ImageClickEventArgs”不包含“RowIndex”的定义,并且找不到可接受类型为“System.Web.UI.ImageClickEventArgs”的第一个参数的扩展方法“RowIndex”(是否缺少 using 指令或程序集引用?) E:\ProgramCode\OnlineTest\OnlineTestWeb\HouAdmin\PaperSet.aspx.cs 92 102 E:\...\OnlineTestWeb\
    这是怎么回事?
      

  3.   

                                    <asp:GridView ID="GridView1" runat="server">
                                        <Columns>
                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    <asp:Label ID="Label24" runat="server" Text="一、单选题"> </asp:Label>
                                                    <br />
                                                    <br />
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <table ID="Table2" align="center" border="0" cellpadding="1" cellspacing="1" 
                                                        width="100%">
                                                        <tr>
                                                            <td colspan="3">
                                                                <asp:Label ID="Label1" runat="server" Text="<%# Container.DataItemIndex+1 %>">
                                                                </asp:Label>
                                                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Que_subject","、{0}") %>'></asp:Label>
                                                                <asp:Label ID="lblSingle" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td width="35%">
                                                                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="Sl" 
                                                                    Text='<%#Eval("OptionA","A、{0}") %>' />
                                                            </td>
                                                            <td width="35%">
                                                                <asp:RadioButton ID="RadioButton2" runat="server" GroupName="Sl" 
                                                                    Text='<%#Eval("OptionB","B、{0}") %>' />
                                                            </td>
                                                            <td>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td width="35%">
                                                                <asp:RadioButton ID="RadioButton3" runat="server" GroupName="Sl" 
                                                                    Text='<%#Eval("OptionC","C、{0}") %>' />
                                                            </td>
                                                            <td width="35%">
                                                                <asp:RadioButton ID="RadioButton4" runat="server" GroupName="Sl" 
                                                                    Text='<%#Eval("OptionD","D、{0}") %>' />
                                                            </td>
                                                            <td>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
      

  4.   

        //将生产试卷保存到数据库    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
        {
            string insertpaper = "insert into Taoti(LessonID,Name,JoinTime) values(" + int.Parse(ddlCourse.SelectedValue) + ",'" + txtPaperName.Text + "','" + DateTime.Now + "');SELECT @@IDENTITY as id";        int afterID = TaoTiManager.GetIDInsert(insertpaper);//保存试卷,并返回自动生成的试卷编号        if (afterID > 0)
            {            foreach (GridViewRow dr in GridView1.Rows)//保存试卷单选题信息
                {
                    string single = "insert into TaotiDetail(TaotiId,Type,TitleID,Mark) values(" + afterID + ",'1'," + int.Parse(((Label)dr.Controls[0].FindControl("lblSingle")).Text) + "," + int.Parse(txtSingleFen.Text) + ")";                TaotiDetailManager.Insert(single);            }            foreach (GridViewRow dr in GridView2.Rows)//保存试卷多选题信息
                {
                    string multi = "insert into TaotiDetail(TaotiId,Type,TitleID,Mark) values(" + afterID + ",'2'," + int.Parse(((Label)dr.Controls[0].FindControl("lblMulti")).Text) + "," + int.Parse(txtMultiFen.Text) + ")";                TaotiDetailManager.Insert(multi);
                }            foreach (GridViewRow dr in GridView3.Rows)//保存试卷填空题信息
                {
                    string Tk = "insert into TaotiDetail(TaotiId,Type,TitleID,Mark) values(" + afterID + ",'3'," + int.Parse(((Label)dr.Controls[0].FindControl("lblTk")).Text) + "," + int.Parse(txtTkFen.Text) + ")";                TaotiDetailManager.Insert(Tk);
                }            foreach (GridViewRow dr in GridView4.Rows)//保存试卷判断题信息
                {
                    string Pd = "insert into TaotiDetail(TaotiId,Type,TitleID,Mark) values(" + afterID + ",'4'," + int.Parse(((Label)dr.Controls[0].FindControl("lblPd")).Text) + "," + int.Parse(txtPdFen.Text) + ")";                TaotiDetailManager.Insert(Pd);
                }            Response.Write("<script language=javascript>alert('保存成功');location='taoti_xinxi.aspx'</script>");
            }
        }搞定了。呵呵。。
      

  5.   

    先找Panel里的Gridview 然后在遍历