hitentempate button asp.net c#

alfinete

Power Member
Código:
 protected void Page_Load(object sender, EventArgs e)
    {
      Random rnd;
      int auxrnd;
      Button bt;
      HiddenField auxHiddenArgument;

      //Session["numescola"]="400282";
      //loaddados();

            foreach (GridViewRow row in grvdocentes.Rows)
              {
                auxrnd = rnd.Next();

                bt = (Button )row.FindControl("btnteste");

                auxHiddenArgument = (HiddenField)row.FindControl("auxHiddenArgument");


                bt.CommandArgument = auxrnd;
               
                auxHiddenArgument.Value = auxrnd;

              }          
       bt.Enabled =false;
    }


como posso fazer para por o bt ficar enable a false,  que é um button que esta dentro de um itentamplate de uma gridview

agradecia uma ajuda
 
tenho este code no page load que funciona

Código:
private void procurabotoes()
    {

      Random rnddocente = new Random();
      Random rndescola = new Random();
      Random rndgrhe = new Random();
      int auxrnddocente, auxrndescola, auxrnddgrhe;
      Button  btdocente, btescola,btdgrhe = new Button();
      HiddenField auxHiddenArgumentdocente, auxHiddenArgumentescola, auxHiddenArgumentdgrhe;

      foreach (GridViewRow row in grvdocentes.Rows)
      {
       
        auxrnddocente = rnddocente.Next();
        auxrndescola = rndescola.Next();
        auxrnddgrhe = rndgrhe.Next();

      

        btdocente = (Button)row.FindControl("btn_licdocente");
        auxHiddenArgumentdocente = (HiddenField)row.FindControl("auxHiddenArgumentdocente");
        btdocente.CommandArgument = Convert.ToString(rnddocente);
        auxHiddenArgumentdocente.Value = Convert.ToString(auxrnddocente);

        btescola = (Button)row.FindControl("btn_escola");
        auxHiddenArgumentescola = (HiddenField)row.FindControl("auxHiddenArgumentescolas");
        btescola.CommandArgument = Convert.ToString(rndescola);
        auxHiddenArgumentescola.Value = Convert.ToString(auxrndescola);

        btdgrhe = (Button)row.FindControl("btn_licdgre"); 
        auxHiddenArgumentdgrhe = (HiddenField)row.FindControl("auxHiddenArgumentdgrhe");
        btdgrhe.CommandArgument = Convert.ToString(rndgrhe);
        auxHiddenArgumentdgrhe.Value = Convert.ToString(auxrnddgrhe);

       


      }          
    }
e este no grid.rowcomand que não esta a funcionar

Código:
 protected void grvdocentes_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      //Type cstype = this.GetType();
      string str_script = "";

      if (e.CommandName == "btnlicdocente")
      {
        //int index = Convert.ToInt32(e.CommandArgument);
        //GridViewRow row = grvdocentes.Rows[index];
        HiddenField auxHiddenArgument ;
           

            foreach  (GridViewRow  row in grvdocentes.Rows)
                {
              
                auxHiddenArgument =(HiddenField)row.FindControl("auxHiddenArgumentdocente");
                if (e.CommandArgument == auxHiddenArgument)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  }
               }
      }

    }


e quando clico no btn docente ele da este erro

Código:
[I]Invalid postback or callback argument.  Event validation is enabled using  <pages enableEventValidation="true"/> in configuration or <%@ Page  EnableEventValidation="true" %> in a page.  For security purposes, this  feature verifies that arguments to postback or callback events originate from  the server control that originally rendered them.  If the data is valid and  expected, use the ClientScriptManager.RegisterForEventValidation method in order  to register the postback or callback data for validation.[/I]


gostava de um help
 
Última edição:
ja resolvi esse erro

referente ao code do rowcommand

Código:
 if (e.CommandName == "btnlicdocente")
      {
        //int index = Convert.ToInt32(e.CommandArgument);
        //GridViewRow row = grvdocentes.Rows[index];
        string auxHiddenArgument="" ;
           

            foreach  (GridViewRow  row in grvdocentes.Rows)
                {

                  auxHiddenArgument = ((HiddenField)row.FindControl("auxHiddenArgumentdocente")).Value;
                if (e.CommandArgument == auxHiddenArgument)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  }
               }
      }
não sei pq nam entra neste if

Código:
  if (e.CommandArgument == auxHiddenArgument)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  }
 
Última edição:
Código:
  protected void Page_Load(object sender, EventArgs e)
    {
     

      Session["numescola"]="400282";
      loaddados();
      procurabotoes();
       
  }




    protected void grvdocentes_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      //Type cstype = this.GetType();
      string str_script = "";

      if (e.CommandName == "btnlicdocente")
      {
        //int index = Convert.ToInt32(e.CommandArgument);
        //GridViewRow row = grvdocentes.Rows[index];
        string auxHiddenArgument="" ;
           

            foreach  (GridViewRow  row in grvdocentes.Rows)
                {
                                                                    
                  auxHiddenArgument = ((HiddenField)row.FindControl("auxHiddenArgumentdocente")).Value;
                string teste= auxHiddenArgument.ToString (); 
                string teste2= e.CommandArgument.ToString (); 
                if (e.CommandArgument.ToString() == auxHiddenArgument)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  break ;
                  }
                 
               }
      }

    }


   private void procurabotoes()
    {
      Dados d= new Dados();
      DataRow dr = null ;
      Random rnddocente = new Random();
      Random rndescola = new Random();
      Random rndgrhe = new Random();
      int auxrnddocente, auxrndescola, auxrnddgrhe;
      Button  btdocente, btescola,btdgrhe = new Button();
      HiddenField auxHiddenArgumentdocente, auxHiddenArgumentescola, auxHiddenArgumentdgrhe;

      foreach (GridViewRow row in grvdocentes.Rows)
      {
       
        auxrnddocente = rnddocente.Next();
        auxrndescola = rndescola.Next();
        auxrnddgrhe = rndgrhe.Next();
      

        btdocente = (Button)row.FindControl("btn_licdocente");
        auxHiddenArgumentdocente = (HiddenField)row.FindControl("auxHiddenArgumentdocente");
        btdocente.CommandArgument = Convert.ToString(rnddocente);
        auxHiddenArgumentdocente.Value = Convert.ToString(auxrnddocente);

        btescola = (Button)row.FindControl("btn_escola");
        auxHiddenArgumentescola = (HiddenField)row.FindControl("auxHiddenArgumentescolas");
        btescola.CommandArgument = Convert.ToString(rndescola);
        auxHiddenArgumentescola.Value = Convert.ToString(auxrndescola);

        btdgrhe = (Button)row.FindControl("btn_licdgre"); 
        auxHiddenArgumentdgrhe = (HiddenField)row.FindControl("auxHiddenArgumentdgrhe");
        btdgrhe.CommandArgument = Convert.ToString(rndgrhe);
        auxHiddenArgumentdgrhe.Value = Convert.ToString(auxrnddgrhe);

       
           string numdocente = row.Cells[2].Text;
           dr = d.Licenca_d (numdocente);
       
             if (dr[11].ToString ()=="t" )  
              {
              btdocente.Enabled =true;
              btescola.Enabled = true;
              btdgrhe.Enabled = true; 
              }
             else
              {
               btdocente.Enabled =true; 
               btescola.Enabled = false;
               btdgrhe.Enabled = false; 
              } 
      }          
    }

aspx

Código:
 <div class="greed2">
        <asp:GridView ID="grvdocentes" runat="server" CellSpacing="2" CellPadding="3" BorderWidth="1px"
            BorderStyle="None" BorderColor="#DEBA84" BackColor="#DEBA84" AutoGenerateColumns="False"
            Width="800px" OnRowCommand="grvdocentes_RowCommand"  >
            <FooterStyle BackColor="#C09E65" ForeColor="#C09E65" />
            <Columns>
                <asp:BoundField FooterText="escola " HeaderText="Escola" DataField="escolaExerce">
                    <ControlStyle Width="150px" />
                    <ItemStyle Width="70px" />
                    <HeaderStyle Width="70px" />
                    <FooterStyle Width="70px" />
                </asp:BoundField>
                <asp:BoundField FooterText="Nome escola exerce" HeaderText="Nome escola" DataField="nome">
                    <ControlStyle Width="600px" />
                    <ItemStyle Width="600px" />
                    <HeaderStyle Width="600px" />
                    <FooterStyle Width="600px" />
                </asp:BoundField>
                <asp:BoundField DataField="docenteId" FooterText="Num docente" HeaderText="Num docente">
                    <ItemStyle Width="100px" />
                    <HeaderStyle Width="100px" />
                    <FooterStyle Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="nomecandidato" FooterText="Nome Docente" HeaderText="Nome Docente">
                    <ItemStyle Width="400px" />
                    <HeaderStyle Width="400px" />
                    <FooterStyle Width="400px" />
                </asp:BoundField>
                <asp:BoundField DataField="descricao" FooterText="tipo" HeaderText="Tipo" />
                <asp:TemplateField FooterText="licensa" HeaderText="licensa">
                    <ItemTemplate>
                        <asp:HiddenField ID="auxHiddenArgumentdocente" runat="server" />
                        <asp:Button ID="btn_licdocente" CssClass="btn_2" runat="server" CommandName="btnlicdocente" Text="Docente" CausesValidation="False" UseSubmitBehavior="False" CommandArgument="btnlicdocente" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField FooterText="licensa" HeaderText="licensa">
                    <ItemTemplate>
                        <asp:HiddenField ID="auxHiddenArgumentescolas" runat="server" />
                        <asp:Button ID="btn_escola" CssClass="btn_2" runat="server" CommandName="btnescola" Text="Escola" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField FooterText="licensa" HeaderText="licensa ">
                    <ItemTemplate>
                        <asp:HiddenField ID="auxHiddenArgumentdgrhe" runat="server" />
                        <asp:Button ID="btn_licdgre" CssClass="btn_2" runat="server" CommandName="btnlicdgre" Text="Dgrhe" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#C09E65" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
        <br />
        &nbsp;&nbsp;
        <asp:Label ID="lbl1" runat="server" Text="Label"></asp:Label></div>

continua a não ir ao tal if não sei porque cargas de agua
 
Código:
  if (e.CommandArgument == e.CommandArgument)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  }

nao sei de será dá assim, mas nao tens o .value para e.CommandArgument e e.CommandArgument ficando algo do genero:

Código:
  if (e.CommandArgument.value == e.CommandArgument.value)
                  {
                  Session["numescola"] = row.Cells[0].Text;
                  Session["numdocente"] = row.Cells[2].Text;
                  //Response.Redirect("listapedidosescola.aspx"); 
                  lbl1.Text = Session["numdocente"].ToString ();
                  }

:confused:
 
Back
Topo