Solved

Gridview  /  HiddenFields  Problem

Posted on 2006-10-23
2
987 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now