2010-11-09 8 views
0

je veux capturer le texte saisi par un utilisateur lors de la mise à jour de commande est pressée de prendre en considération que je Changed Edit et mise à jour de commande Pour être nommé Activerzone de texte à l'intérieur EditTemplate dans un Datagrid est retourne le texte vide

<asp:DataGrid ID="Datagrid1" runat="server" AutoGenerateColumns="False" Width="100%" 
    OnCancelCommand="Datagrid1_CancelCommand" OnEditCommand="Datagrid1_EditCommand" 
    OnUpdateCommand="Datagrid1_UpdateCommand"> 
    <Columns> 
     <asp:TemplateColumn> 
       <EditItemTemplate> 
       <table cellpadding="0" cellspacing="0" width="100%"> 
        <tr> 
         <td align="center" style="width: 200px; white-space: nowrap;"> 
          <asp:Label ID="Label1" runat="server" Text='<%# Eval("Reg_FullName") %>'></asp:Label> 
         </td> 
         <td align="center" style="width: 100px;"> 
          <asp:Label ID="lbl_User" runat="server" Text='<%# Eval("Reg_UserName") %>'></asp:Label> 
         </td> 
         <td align="center" style="width: 100px;"> 
          <asp:Label ID="lbl_AddedAt" runat="server" Text='<%# Eval("Reg_ActivatedAt") %>'></asp:Label> 
         </td> 
         <td align="center" style="width: 100px;"> 
          <asp:Label ID="lbl_IsAct" runat="server" Text='<%# Eval("Reg_IsActive") %>'></asp:Label> 
         </td> 
         <td align="center" style="width: 100px;"> 
          <asp:Label ID="lbl_Days" runat="server" Text="<%$ Resources:Okaz, DaysNum %>"></asp:Label> 
         </td> 
         <td align="center" style="width: 100px;"> 
          <asp:TextBox ID="Hello_txt" runat="server"></asp:TextBox> 
         </td> 
        </tr> 
       </table> 
      </EditItemTemplate></asp:TemplateColumn> 
     <asp:EditCommandColumn CancelText="Cancel" EditText="Activate" 
      UpdateText="Activate"></asp:EditCommandColumn> 

bien et mon code est derrière:

protected void Datagrid1_EditCommand(object source, DataGridCommandEventArgs e) 
    { 
     Datagrid1.EditItemIndex = e.Item.ItemIndex; 
     try 
     { 
      SqlDataSource1.SelectCommand = "Select * from OkazRegisteration"; 
      Datagrid1.DataSourceID = SqlDataSource1.ID; 
      Datagrid1.DataBind(); 
     } 
     catch (Exception ex) 
     { 
      ErrorLabel.Text = ex.ToString(); 
     } 
    } 

    protected void Datagrid1_CancelCommand(object source, DataGridCommandEventArgs e) 
    { 
     Datagrid1.EditItemIndex = -1; 
     try 
     { 
      SqlDataSource1.SelectCommand = "Select * from OkazRegisteration"; 
      Datagrid1.DataSourceID = SqlDataSource1.ID; 
      Datagrid1.DataBind(); 
     } 
     catch (Exception ex) 
     { 
      ErrorLabel.Text = ex.ToString(); 
     } 
    } 

    protected void Datagrid1_UpdateCommand(object source, DataGridCommandEventArgs e) 
    { 

     switch (e.Item.ItemType) 
     { 
      case ListItemType.EditItem: 

       TextBox txt_Days = (TextBox)e.Item.FindControl("Hello_txt"); 
       Label lbl_User = (Label)e.Item.FindControl("lbl_User"); 

       SqlDataSource2.UpdateCommand = "Update OkazRegisteration set Reg_IsActive='True', Reg_ExpiryDays=" + txt_Days.Text + " , Reg_ActivatedAt='" + DateTime.Now.ToShortDateString() + "' Where Reg_UserName='" + lbl_User.Text + "'"; 
       SqlDataSource2.Update(); 
       break; 
     } 
     try 
     { 
      SqlDataSource1.SelectCommand = "Select * from OkazRegisteration"; 
      Datagrid1.DataSourceID = SqlDataSource1.ID; 
      Datagrid1.DataBind(); 
     } 
     catch (Exception ex) 
     { 
      ErrorLabel.Text = ex.ToString(); 
     } 
    } 

dans le Datagrid1_UpdateCommand

la valeur du texte de la zone de texte txt_Days est toujours vide

Qu'est-ce que je fais mal ??

Je l'ai fait ce genre de travail pour un temps très long, mais je ne vois pas l'erreur cette fois-ci

S'il vous plaît Aide,

Cordialement.

+0

Vous pouvez utiliser Text = « <%# Bind() %> » pour définir la valeur de la zone de texte; ce serait beaucoup plus simple. En outre, avec la façon dont vous construisez votre chaîne SQL, quelqu'un pourrait détruire votre base de données en soumettant la mauvaise chose. Mais à part ça ... je ne sais pas pourquoi vous ne voyez pas votre texte. Etes-vous sûr que le txt_Days est trouvé? – GendoIkari

Répondre

0

J'ai découvert que je lia ma grille chaque fois que la page se charge de sorte que le texte à l'intérieur de ma zone de texte soit effacé.

espoir qui donne une touche à tout le monde fait face à la même question

Questions connexes