0

I've been utilizing what I call, "drag, drop and configure" programming for years to create very simple ASP.net forms to collect data for my organization. Basically, I'll drag a datasource into my design view, configure it, and then I'll drag a gridview into the design view and then configure it, etc., etc.

Yesterday, I encountered a behavior I have never seen. My gridview is set to allow row selection. Everything seemed to be working normally until I happened to click on a row that didn't "select" (didn't highlight itself, etc.). And, then I started clicking on other rows and found more that couldn't be selected. Again -- it's not all the rows...just some. i.e. some can be selected and others can't.

After a lot of troubleshooting, the only thing I've been able to determine is that above a certain datakey value -- rows won't select. In this case, its datakeys with values around and > 40,000. Anything below that, and the rows select and the other parts of the form load just fine. The fact that it works for all records with datakeys below a certain value is really stumping me as to what rock to look under next -- hence, actually creating a stackoverflow account and posing the question.

Code for the gridview is below. It does live within an update panel if that matters. Also provided the code behind, though it's not really doing anything of consequence.

Note:

  1. The datakey that seems to be controlling the behavior is a unique identifier for an application within a set of applications. It's not an incremental identity. --- if that helps.
  2. The form is hooked into a database for the select statement and is pulling records from a view to populate the grid.
  3. I'm tempted to show all of my code including the database side and stored procs -- thinking maybe I'm making rookie mistakes with data typing, etc. --- BUT --- I'm pausing there because the gridview selection IS WORKING -- just not above datakeys around and above 40,000
  4. Lastly, when you attempt to select an item with a key > 40,000 the grid will no longer sort by columns or allow you to click a different page. Similarly, if you sort the grid FIRST by applicationID (the datakey) -- all the pages with datakeys > 40,000 are not clickable i.e. pagination for those pages do not work

EDIT --- DANG IT!!! I posted the wrong code behind. I replaced it with the right one. UPDATE: It looks like it's related to the panels. When I comment them out --- it works. When they are included -- the rows in question (keys > 40000) aren't selectable. All this code does is control visibility of panels. How could visibility properties make this kind of impact....weird

Pic of Issue:

Pic of Issue

  <ContentTemplate>
                <strong>
                <asp:ScriptManager ID="ScriptManager2" runat="server">
                </asp:ScriptManager>
                Select AIT by using search box below or by sorting and paging through AIT table.<br />
                <br />
                Search:&nbsp; </strong>&nbsp;<asp:TextBox ID="TxtAITSearch" runat="server"></asp:TextBox>
                &nbsp;&nbsp;&nbsp;
                <asp:Button ID="btn_Search" runat="server" OnClick="btn_Search_Click" Text="Search" />
                <em>
                <br />
                *wildcard searches for AIT number, AIT Name or AIT Manager may be used</em><asp:HiddenField ID="hdnApl_ID" runat="server" />
                <asp:HiddenField ID="hdn_StandardID" runat="server" />
                <asp:HiddenField ID="Hdn_AlignmentID" runat="server" />
                <asp:HiddenField ID="hdn_Attribute" runat="server" />
                <br />
                <asp:GridView ID="gvAITSelect" runat="server" AllowPaging="True" AllowSorting="True"  AutoGenerateColumns="False" CellPadding="3" DataKeyNames="applicationID" DataSourceID="DSGetSearchView" GridLines="Vertical" OnSelectedIndexChanged="gvAITSelect_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">
                    <AlternatingRowStyle BackColor="#DCDCDC" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="applicationID" HeaderText="App ID" SortExpression="applicationID" />
                        <asp:BoundField DataField="fullName" HeaderText="Application" SortExpression="fullName" />
                        <asp:BoundField DataField="Alignment" HeaderText="Alignment" SortExpression="Alignment" />
                        <asp:BoundField DataField="AlignmentID" HeaderText="AlignmentID" SortExpression="AlignmentID" Visible="False" />
                        <asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
                        <asp:BoundField DataField="relatedAssociates_2_displayName" HeaderText="App Mgr" SortExpression="relatedAssociates_2_displayName" />
                        <asp:BoundField DataField="relatedAssociates_3_displayName" HeaderText="Tech Exec" SortExpression="relatedAssociates_3_displayName" />
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#0000A9" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#000065" />
                </asp:GridView>

 protected void gvAITSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            lbl_Alignment.Text = gvAITSelect.SelectedRow.Cells[3].Text;
            Hdn_AlignmentID.Value = gvAITSelect.SelectedRow.Cells[4].Text;
          

            string strAITvalue = gvAITSelect.SelectedRow.Cells[1].Text;
            hdnApl_ID.Value = strAITvalue.ToString();

            //panel_RoleDetails.Visible = true;
            //panel_AITAlignment.Visible = true;
            //panel_NoteDetails.Visible = true;
        }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • You mentioned 40000. does your dataset really have 40k+ rows? if so, first try to reduce the dataset to contain say about 40 rows above the 40000 range. Also, the `DataKeyNames` property of the `GridView` are typically the database pkey for the row, not that this should affect row selection. Also, fields in `DataKeyNames` and other kinds of pkeys are typically not supposed to be displayed to the user. – fnostro Apr 20 '22 at 18:20
  • Thanks fnostro -- No, the result set only has 118 rows. The App ID (datakey) is a primary key (though I don't have it set as such). It is the unique identifier for these records which are applications. Our users know applications by their numbers - or this particular datakey which is why it's displayed. You did give me an idea -- I willl try setting this field as an actual primary key. If you I don't post back -- it didn't work. Thanks again. – 10 Print ''My Name'' Apr 20 '22 at 19:05
  • No - that won't affect row selection. Try commenting out the update panel and relevant code. Those have caused me no end of grief. – fnostro Apr 20 '22 at 19:24
  • I think you might be onto something. I updated my original post. See the bold. When I noticed I posted wrong code behind -- just for giggles I commented out the panels like you see above....and the rows are selectable. Which -- I'm thankful for a new troubleshooting path - -but like I said above...how in the world would visibility properties present this kind of issue. Very weird. – 10 Print ''My Name'' Apr 20 '22 at 19:47
  • short answer: visibility wouldn't have that effect. what does the rendered html look like for that section in the graphic? – fnostro Apr 20 '22 at 20:04
  • Well, actually, setting controls visible = false can be source of many issues - remember, when you do that, the control and HTML markup is NOT sent to the client side anymore. This can often wreak havoc for client side js code. Often, what works better is to set the style with display:none, since that hides the control, but it STILL renders in the HMTL. I don't see any js (JavaScript) code here, but using visible can often cause issues, since as noted, asp.net does not send the controls to the client side anymore for controls with visible=false. – Albert D. Kallal Apr 21 '22 at 01:10
  • @fnostro -- Since I'm a new poster, I don't have perms to post pics in line -- but I did provide a pic which is available in a stackoverflow link above – 10 Print ''My Name'' Apr 21 '22 at 13:37
  • @AlbertD.Kallal -- thanks -- I'm not using any javascript code -- (I don't think). I'm just configuring properties of the controls on events. That may actually be using javascript under the hood -- I'm not sure. And, you have given me a work around that I think is viable via setting the style. It's still very perplexing why the visibility property works for datakeys < 40000 but not keys higher than that. Thank you very much for your input! – 10 Print ''My Name'' Apr 21 '22 at 13:41
  • It not clear what exactly is going on here. Is that column a text or number column? (might be something in that area). I only point out that compared to say desktop, the behavior of turning off display of a control with visible = false works significantly different - and when you do that, the control is not only hidden but ALSO not rendered in the client browser side - so, it may well not be the issue here, but often visible = false can cause problems on a page, since that control in fact does not exist on the page anymore - hence this can be counter intuitively to many new to web land. – Albert D. Kallal Apr 21 '22 at 13:58

1 Answers1

0

Ok -- I figured it out. And, the answer is, I'm a big dummy. Further, the fact that the grid stopped working around in and around 40000 should have been a big flashlight to me pointing the way. Pic of the issues

If you look at the pic I uploaded -- in the course of troubleshooting an earlier and unrelated issue -- I set the DbType (highlighted row) to Int16. In the available selections I don't see an unsigned Int16 -- so, this appears to be signed---Annnnnnnnnnnnnnnnd, of course, good developers know Int16s hold values up to 32,767. Guess what happened when I changed it back to the default "Object"? Yup. It worked. So the problem not at all weird or strange. Instead, very much a rookie mistake.

All this said -- good learning experience. Additionally, @Albert D. Kallal and @fnostro you both gave me some good understanding on some things for the future. I appreciate both of you trying to help me. And, now I also, have a stackoverflow account :)

Thanks again.