Solved

Gridview  /  HiddenFields  Problem

Posted on 2006-10-23
2
994 Views
Last Modified: 2012-06-27
I’ve got this really bad gridview problem that’s crippling my schedule.   I’m adding hidden fields to gridview rows during rowdatabound so I can use them during user processing.  The problem is that values in the output hidden fields don’t match the values in the input datatable.

The code below is a simplified version of the setup, but it accurately reflects the problem. (I’ve got code like this working properly in a previous draft, but that was on the other side of an extensive revision...not a good place to go.)

It should be simple, assuming that the rowdatabound doesn’t care where the row comes from, and the gridview only pays attention to the rowdatabound output when it then goes on to render the row.  

But something else must be going on, because the html that shows up on the page has different values than the row databound results.

The source is an objectdatasource, and the way the table is constructred is fairly complicated, but I run another “vanilla” gridview of the same table on the same page, and the data looks exactly right

I’m looking for anyway possible to understand what might be going on here, because I’ve run out of ways to even diagnose it.

Any suggestions on the inner workings of the Gridview, or how the rowdatabound might NOT be independent of the table that’s handed to it by the objectdatasource, or what might happen between rowdatabound and final HTML output, or any points that I might investigate, or any thoughts about this at all, would be greatly appreciated.

Thanks!


‘===============GRIDVIEW DECLARATION===============

<asp:GridView ID="GLGV" runat="server" AutoGenerateColumns="False"
       DataSourceID="GLGVDataSource1"
       BorderColor="#888888" BackColor="White" BorderWidth="1px"
       ForeColor="Black" Height="10px" cssclass = "GLGV1" ShowHeader="False" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="PRTS" runat="server" CssClass="Prts01">
     
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>

        <RowStyle BackColor="White" ForeColor="Black" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="MistyRose" Font-Bold="True" ForeColor="#111111" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
</asp:GridView>

‘===============ROWDATABOUND PROCESSING =================

Protected Sub GLGV_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GLGV.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.DataRow

Dim wrkRow As DataRowView = CType(e.Row.DataItem, DataRowView)

Dim wrkPanel As Panel = e.Row.Cells(0).Controls(0).FindControl("PRTS")
Dim wrkPanelControls As ControlCollection = wrkPanel.Controls

Debug.WriteLine("---------- Row Input Values -----------")
Debug.WriteLine("PrtTyp - " & wrkRow("PartType"))
Debug.WriteLine("OTLID - " & wrkRow("OTLID"))
Debug.WriteLine("ParentID - " & wrkRow("OTLParentID"))
Debug.WriteLine("----------------------------------")


Dim wrkSel As New GLFSelectButton
wrkSel.ID = "G1SL"
wrkPanelControls.Add(wrkSel)

Dim wrkH1 As New HiddenField
wrkH1.ID = "OTLID01"
wrkH1.Value = wrkRow("OTLID")
wrkPanelControls.Add(wrkH1)
'---------------------
Dim wrkH2 As New HiddenField
wrkH2.ID = "OTLParentID01"
wrkH2.Value = wrkRow("OTLParentID")
wrkPanelControls.Add(wrkH2)
'---------------------
Dim wrkH3 As New HiddenField
wrkH3.ID = "PartType01"
wrkH3.Value = wrkRow("PartType")
wrkPanelControls.Add(wrkH3)

Dim wrkHR As New HtmlTableRow
wrkHR.Style.Add("height", "auto")

Dim L1 As New Label
L1.Text = "&nbsp;&nbsp;&nbsp;"
L1.Style.Add("width", Trim(Str(50)) & "px")
L1.Style.Add("overflow", "hidden")
L1.Text = wrkRow("PartType")

Dim c1 As New HtmlTableCell
c1.Style.Add("height", "20px")
c1.Width = L1.Width.ToString
c1.Controls.Add(L1)
wrkHR.Cells.Add(c1)
wrkHR.Cells.Add(c1)

Dim wrkHT As New HtmlTable
wrkHT.Style.Add("height", "auto")
wrkHT.Style.Add("margin-top", "-2px")
wrkHT.Style.Add("margin-bottom", "-2px")
wrkHT.Rows.Add(wrkHR)
wrkPanelControls.Add(wrkHT)

Debug.WriteLine("----------Hidden Field Values-----------")
Debug.WriteLine("PrtTyp - " & wrkH3.Value)
Debug.WriteLine("OTLID - " & wrkH1.Value)
Debug.WriteLine("ParentID - " & wrkH2.Value)
Debug.WriteLine("----------------------------------")


End Select

‘===============DEBUG OUTPUT FROM ABOVE==================


---------- Row Input Values -----------
PrtTyp - CLMN
OTLID - 1709
ParentID - 1708
----------------------------------
----------Hidden Field Values-----------
PrtTyp - CLMN
OTLID - 1709
ParentID - 1708
----------------------------------




---------- Row Input Values -----------
PrtTyp - OWNR
OTLID - 1713
ParentID - 1709
----------------------------------
----------Hidden Field Values-----------
PrtTyp - OWNR
OTLID - 1713
ParentID - 1709
----------------------------------




---------- Row Input Values -----------
PrtTyp - HPLT
OTLID - 1710
ParentID - 1708
----------------------------------
----------Hidden Field Values-----------
PrtTyp - HPLT
OTLID - 1710
ParentID - 1708
----------------------------------




---------- Row Input Values -----------
PrtTyp - CLMN
OTLID - 1711
ParentID - 1708
----------------------------------
----------Hidden Field Values-----------
PrtTyp - CLMN
OTLID - 1711
ParentID - 1708
----------------------------------

‘=========RESULTING HTML =============

<DIV class=Prts01 id=GLGV_ctl02_PRTS><IMG onmouseup=RspSel(this) class=GLBtn onmousedown=ShwPrsBtn(this) id=GLGV_ctl02_G1SL style="BORDER-TOP-WIDTH: 0px; MARGIN-TOP: 2px; BORDER-LEFT-WIDTH: 0px; LEFT: 2px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 16px; POSITION: absolute; HEIGHT: 16px; BORDER-RIGHT-WIDTH: 0px" src="../../App_Images/Sel.bmp">

<INPUT id=GLGV_ctl02_OTLID01 type=hidden value=1709 name=GLGV$ctl02$OTLID01>

<INPUT id=GLGV_ctl02_OTLParentID01 type=hidden value=1708 name=GLGV$ctl02$OTLParentID01>

<INPUT id=GLGV_ctl02_PartType01 type=hidden value=CLMN name=GLGV$ctl02$PartType01>

<TABLE style="MARGIN-TOP: -2px; MARGIN-BOTTOM: -2px; HEIGHT: auto">
<TBODY>
<TR style="HEIGHT: auto">
<TD style="HEIGHT: 20px"><SPAN style="OVERFLOW: hidden; WIDTH: 50px">CLMN</SPAN></TD></TR></TBODY></TABLE></DIV></TD></TR>
<TR style="COLOR: black; BACKGROUND-COLOR: white">


<TD>
<DIV class=Prts01 id=GLGV_ctl03_PRTS><IMG onmouseup=RspSel(this) class=GLBtn onmousedown=ShwPrsBtn(this) id=GLGV_ctl03_G1SL style="BORDER-TOP-WIDTH: 0px; MARGIN-TOP: 2px; BORDER-LEFT-WIDTH: 0px; LEFT: 2px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 16px; POSITION: absolute; HEIGHT: 16px; BORDER-RIGHT-WIDTH: 0px" src="../../App_Images/Sel.bmp">

<INPUT id=GLGV_ctl03_OTLID01 type=hidden value=1710 name=GLGV$ctl03$OTLID01>

<INPUT id=GLGV_ctl03_OTLParentID01 type=hidden value=1708 name=GLGV$ctl03$OTLParentID01>

<INPUT id=GLGV_ctl03_PartType01 type=hidden value=HPLT name=GLGV$ctl03$PartType01>


<TABLE style="MARGIN-TOP: -2px; MARGIN-BOTTOM: -2px; HEIGHT: auto">
<TBODY>
<TR style="HEIGHT: auto">
<TD style="HEIGHT: 20px"><SPAN style="OVERFLOW: hidden; WIDTH: 50px">OWNR</SPAN></TD></TR></TBODY></TABLE></DIV></TD></TR>
<TR style="COLOR: black; BACKGROUND-COLOR: white">
<TD>
<DIV class=Prts01 id=GLGV_ctl04_PRTS><IMG onmouseup=RspSel(this) class=GLBtn onmousedown=ShwPrsBtn(this) id=GLGV_ctl04_G1SL style="BORDER-TOP-WIDTH: 0px; MARGIN-TOP: 2px; BORDER-LEFT-WIDTH: 0px; LEFT: 2px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 16px; POSITION: absolute; HEIGHT: 16px; BORDER-RIGHT-WIDTH: 0px" src="../../App_Images/Sel.bmp">

<INPUT id=GLGV_ctl04_OTLID01 type=hidden value=1711 name=GLGV$ctl04$OTLID01>

<INPUT id=GLGV_ctl04_OTLParentID01 type=hidden value=1708 name=GLGV$ctl04$OTLParentID01>

<INPUT id=GLGV_ctl04_PartType01 type=hidden value=CLMN name=GLGV$ctl04$PartType01>

<TABLE style="MARGIN-TOP: -2px; MARGIN-BOTTOM: -2px; HEIGHT: auto">
<TBODY>
<TR style="HEIGHT: auto">
<TD style="HEIGHT: 20px"><SPAN style="OVERFLOW: hidden; WIDTH: 50px">HPLT</SPAN></TD></TR></TBODY></TABLE></DIV></TD></TR>
<TR style="COLOR: black; BACKGROUND-COLOR: white">


<TD>
<DIV class=Prts01 id=GLGV_ctl05_PRTS><IMG onmouseup=RspSel(this) class=GLBtn onmousedown=ShwPrsBtn(this) id=GLGV_ctl05_G1SL style="BORDER-TOP-WIDTH: 0px; MARGIN-TOP: 2px; BORDER-LEFT-WIDTH: 0px; LEFT: 2px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 16px; POSITION: absolute; HEIGHT: 16px; BORDER-RIGHT-WIDTH: 0px" src="../../App_Images/Sel.bmp">

<INPUT id=GLGV_ctl05_OTLID01 type=hidden value=1711 name=GLGV$ctl05$OTLID01>

<INPUT id=GLGV_ctl05_OTLParentID01 type=hidden value=1708 name=GLGV$ctl05$OTLParentID01>

<INPUT id=GLGV_ctl05_PartType01 type=hidden value=CLMN name=GLGV$ctl05$PartType01>


<TABLE style="MARGIN-TOP: -2px; MARGIN-BOTTOM: -2px; HEIGHT: auto">
<TBODY>
<TR style="HEIGHT: auto">
<TD style="HEIGHT: 20px"><SPAN style="OVERFLOW: hidden; WIDTH: 50px">CLMN</SPAN></TD></TR></TBODY></TABLE></DIV></TD></TR></TBODY></TABLE></DIV>
0
Comment
Question by:codequest
2 Comments
 
LVL 2

Author Comment

by:codequest
ID: 17798058
Resolution:   I redid this test so that it would output Labels with the same text values as the values of the hidden fields.  The label values were correct.   I then did some research on Gridview hiddenfields and found postings that said databinding of hiddenfields was not supported.   Even though I was doing these "manually" that was enough for me...and if I hadn't gotten this to work in the earlier version I wouldn't have stuck with trying to make it work when it failed.   Anyway, I converted the hiddenfields to {display:none} fields and converted my javascript to look for span.innerText, and it seems to be working fine, both in appearance and function.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17807069
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question