When I click the ASP Button to fire off my function, it traverses through the gridview, but the values are empty strings. the point of what I am trying to do is allow my users to reorder the gridview via "Drag and Drop" and then all them to save the new order of the items in the gridview. Here is the catch, when they click the button, I want to traverse through the first column in the Gridview to see if any rules were broken in terms of reordering, and if no rules were broken... the sortOrder (Hidden Column) will be updated. Then the new reordering and updated SortOrder values will be passed back to the database table via stored procedure.
So Far I am at the point where I click the button to traverse through the first column of the gridview via nested for loop, and as I traverse, no values are being picked up. They are all being seen as empty strings.
Here is the Gridview ASPX CODE:
<asp:GridView ID="gridComments" runat="server" BackColor="White" BorderColor="#999999" DataKeyNames="RecNo" OnRowDeleting="gridComments_RowDelete" OnSelectedIndexChanged="gridComments_SelectedIndexChanged"
OnRowDataBound="gridComments_RowDataBound" OnRowUpdating="gridComments_RowUpdating" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="False" Width="90%">
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemStyle Wrap="false" />
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkEdit" CommandName="select" Text='<%# Eval("Program") %>' CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemStyle Width="80%" HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label runat="server" ID="lblDescription" Text='<%# Eval("Preview") %>'></asp:Label>
<asp:LinkButton runat="server" ID="lnkEditComment" Text="Edit"></asp:LinkButton>
<ajaxToolkit:ModalPopupExtender ID="modalPopup" runat="server" PopupControlID="pnlCommentInfo" TargetControlID="lnkEditComment" BackgroundCssClass="modalBackground" CancelControlID="btnCancel"></ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlCommentInfo" runat="server" Style="display: none; text-align: left" CssClass="pnlPop" BorderStyle="Double" Width="500px" ScrollBars="Auto">
<asp:Label runat="server" ID="lblCommentNumber"></asp:Label><br />
<br />
Comment:<br />
<asp:TextBox ID="txtEditComment" runat="server" Rows="6" TextMode="MultiLine" Columns="58" /><br />
<br />
<asp:Button ID="btnSave" runat="server" Text="Save" CausesValidation="false" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" />
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkDelete" CommandName="delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderStyle CssClass =" HiddenCol"/>
<ItemStyle CssClass ="HiddenCol" />
<ItemTemplate >
<%# Eval("SortOrder") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div style="clear:both">
<asp:Button ID="HiddenButton" runat="server" Text="" style="display:none" BackColor="Transparent" Width="30px"/>
<asp:Button ID="Button1" runat="server" OnClick="SaveReorder_Click" Text="Save Ordering Changes" />
</div>
<asp:Panel ID="StatusPanel" runat="server" CssClass="modalPopup" Height="123px" Width="292px" style="display:none">
<div style="text-align: center">
<p> ERROR: Please place comments by program in numerical order from least to greatest. Please try again.
</p>
<div style="text-align: center; height: 21px" >
<input id="OK" type="button" value="OK" />
</div>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground" PopupControlID="StatusPanel" OkControlID="OK" CancelControlID="OK" TargetControlID="HiddenButton">
</ajaxToolkit:ModalPopupExtender>
</div>
Here is the Function I created in Code Behind File:
I am only at the step where, if they reorder the data wrong then a Popup Appears. if they do it correctly then the updates can be saved to the database after updating the SortOrder Column (Hidden Column)
protected void SaveReorder_Click(object sender, EventArgs e)
{
for (int i = 0; i < gridComments.Rows.Count -1; i++ )
{
for(int j = i+1; j < gridComments.Columns.Count ; j++)
{
//if (Convert.ToInt32(gridComments.Rows[i].Cells[0].Text) > Convert.ToInt32(gridComments.Rows[j].Cells[0].Text))
if (Convert.ToInt32(gridComments.Rows[i].Cells[0].Text) > Convert.ToInt32(gridComments.Rows[j].Cells[0].Text))
{
ModalPopupExtender1.Show();
}
}
}
}```