Link to home
Create AccountLog in
Avatar of Michael Sterling
Michael SterlingFlag for United States of America

asked on

Why can I not capture the value of this TextBox within my GridView control?

I have an application written in ASP .NET 3.5 [C#]

Within one of my Gridview controls lives a Textbox (inside a Template field inside an ItemTemplate).

my GridView        

<asp:GridView ID="gdvAllStudentInfo" runat="server" AutoGenerateColumns="false" CssClass="SignedInGrid"
            GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="10" PageIndex="0"
            DataKeyNames="AthleteInfoUid" PagerStyle-HorizontalAlign="Center" OnRowDataBound="gdvAllStudentInfo_OnRowDataBound"
            OnRowCommand="gdvAllStudentInfo_OnRowCommand" OnPageIndexChanging="gdvAllStudentInfo_OnPageIndexChanging">
            <Columns>
                <asp:TemplateField HeaderText="Student ID" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentUid" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteUID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Student Name" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentName" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Sport / Team" ItemStyle-CssClass="StudentName" Visible="false">
                    <ItemTemplate>
                        <asp:Label ID="lblSportTeam" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("SportUid") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Required Hours" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:TextBox ID="tbxRequiredHours" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("RequiredHours") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Sport / Team" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:DropDownList runat="server" ID="ddlSportTeam" Width="210px">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lkbtnDeleteStudentRecord" Text="Delete Student"
                            CommandName="DeleteStudentRecord" CommandArgument='<%# Eval("AthleteUid") %>'
                            CssClass="button small green" />
                        <asp:LinkButton runat="server" ID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            Text="Delete this record" CommandName="DeleteStudentRecord" CommandArgument='<%# Eval("AthleteUid") %>'
                            CssClass="button small green" Visible="false" />
                        <act:ModalPopupExtender ID="deleteModalPopupExtender" runat="server" CancelControlID="btnCancel"
                            OkControlID="btnDelete" TargetControlID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            PopupControlID="divDeleteConfirmation" BackgroundCssClass="modalBackground" />
                        <act:ConfirmButtonExtender ID="deleteConfirmButtonExtender" runat="server" TargetControlID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            Enabled="True" DisplayModalPopupID="deleteModalPopupExtender" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lkbtnSaveChanges" Text="Save Changes" CommandName="SaveChanges"
                            CommandArgument='<%# Eval("AthleteUid") %>' CssClass="button small green" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerSettings Mode="NextPrevious" />
            <PagerStyle CssClass="Paging" />
            <PagerTemplate>
                <div class="Paging">
                    <asp:LinkButton ID="PreviousLinkButton" runat="server" CommandArgument="Prev" CommandName="Page"
                        CssClass="PagerControl" Text="Prev"></asp:LinkButton>
                    <asp:Label ID="PageDescriptionLabel" runat="server" CssClass="PagerControl"></asp:Label>
                    <asp:LinkButton ID="NextLinkButton" runat="server" CommandArgument="Next" CommandName="Page"
                        CssClass="PagerControl" Text="Next"></asp:LinkButton>
                </div>
            </PagerTemplate>
        </asp:GridView>

Open in new window


The datasource of the Gridview is bound when the page loads and so the Textbox mentioned earlier get's populated with a value. On the page, after I edit the value in that text box, I attempt to save the change, by clicking a button. In the code behind, in the OnRowCommand event of my grid I have the following code:


protected void gdvAllStudentInfo_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteStudentRecord")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            //int athleteuid = Convert.ToInt32(e.CommandArgument);
            myGlobalVars.studentID = e.CommandArgument.ToString();

            //divDeleteConfirmation.Visible = true;
            AjaxControlToolkit.ModalPopupExtender deleteModalPopupExtender = (AjaxControlToolkit.ModalPopupExtender)row.FindControl("deleteModalPopupExtender");

            deleteModalPopupExtender.Show();
            //Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&DeleteStudent={1}", AccessLevel, athleteuid.ToString()));                  
        }
        else if (e.CommandName == "SaveChanges")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            string athleteuid = e.CommandArgument.ToString();

            TextBox tbxRequiredHours = (TextBox)row.FindControl("tbxRequiredHours");
            DropDownList ddlSportTeam = (DropDownList)row.FindControl("ddlSportTeam");

            if (Utility.UpdateStudentInfoFromAllStudentsGrid(athleteuid, tbxRequiredHours.Text.ToString(), ddlSportTeam.SelectedIndex))
                Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&SuccessfulUpdate=yes", AccessLevel, athleteuid.ToString()));
            else
                Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&SuccessfulUpdate=no", AccessLevel, athleteuid.ToString()));
        }

    }

Open in new window



No matter what I change the original value to in the TextBox, when it get's to the point of trying to save the data, this line:

if (Utility.UpdateStudentInfoFromAllStudentsGrid(athleteuid, tbxRequiredHours.Text.ToString(), ddlSportTeam.SelectedIndex))

the value of  tbxRequiredHours.Text.ToString() remains the original value, instead of the new value that I put in. Why is that, and how do I capture the changed value in my TextBox?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Michael Sterling

ASKER

@mas_oz2003: CORRECT-O-MUNDO! that was the issue. that's how i do it in my other pages but just didn't think to look at that as a cause. thanks!
@mas_oz2003: CORRECT-O-MUNDO! that was the issue. that's how i do it in my other pages but just didn't think to look at that as a cause. thanks!