开发者

Text Box inside EditTemplate in a Datagrid is returns empty text

i want to Capture the the Text Entered by a user when the update Command is Pressed taking into Consideration that i Changed the Edit and Update Command To be named Activate

 <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>

Well and my code behind is :

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.开发者_C百科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();
        }
    }

in the Datagrid1_UpdateCommand

The Text Value of the TextBox txt_Days is always empty

What am i doing wrong ??

I've done this kind of work for a really long time , but i cannot see the error this time

Please Help,

Regards.


I found out that I am binding my grid every time the page loads so that the text inside my text box is erased.

Hope that gives a hint to anyone faces the same issue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜