Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGrid & ViewState & TemplateColumns

Posted on 2004-08-27
9
Medium Priority
?
455 Views
Last Modified: 2008-02-01
Hi,
I'm using TemplateColumns to cut down on the amount of viewstate my datagrid takes up.  I need my datagrid to be able to sort, so I can't completely disable the viewstate.

I've ran into a bit of a pickle though, which is really confusing me as to why it is doing this.  I need a hyperlink in one of the columns, so when you click on it, some javascript will run.  Here is my code within the datagrid.

--This template column takes up no additional viewstate
<asp:templatecolumn>
  <itemtemplate>
    <a href="#" onclick="someFunction('123456789);">Select</a>
  </itemtemplate>
</asp:templatecolumn>

--This template column takes up oogles of viewstate...The bound column is a value of 9 digits
<asp:templatecolumn>
  <itemtemplate>
    <a href="#" onclick="someFunction('<%# DataBinder.Eval(Container.DataItem, "myColumn"')">Select</a>
  </itemtemplate>
</asp:templatecolumn>

I don't understand this, I'm not using a webcontrol, so I don't see how the datagrid can persist this in the viewstate, anyone offer any help as how I can get this to function correctly, without taking up a ton of viewstate?

--Michael
0
Comment
Question by:raterus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11914438
You could always write your own little sort routine and then rebind to free up the viewstate space, something like this:

 Private Sub dg_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dg.SortCommand
        Dim cnn As New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("EmeraldConnStr"))
        Dim cmd As New SqlClient.SqlCommand
        Dim da As New SqlClient.SqlDataAdapter(cmd)
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim Query As String
        Dim SortString, SortOrder As String
        If Session("SortOrder") = "" Then
            SortOrder = "ASC"
        End If
        If Session("SortOrder") = "ASC" Then
            SortOrder = "DESC"
        End If
        If Session("SortOrder") = "DESC" Then
            SortOrder = "ASC"
        End If
        Query = "SELECT * FROM sschecter.JobNumbers JN ORDER BY JN." & e.SortExpression.ToString & " " & SortOrder
        Session("SortOrder") = SortOrder
        cmd.CommandText = Query
        cmd.Connection = cnn
        cnn.Open()
        da.SelectCommand = cmd
        da.Fill(dt)
        dg.DataSource = dt
        dg.DataKeyField = "JobNumber"
        dg.DataBind()
        cnn.Close()
        cmd.Dispose()
        cnn.Dispose()
        dg.Visible = True
    End Sub

Regards,

Aeros
0
 
LVL 33

Author Comment

by:raterus
ID: 11914555
This problem doesn't have to do with the columns being about to sort, the templatecolumns are the displayed data that is being sorted.  

I've got quite a nice little setup for sorting already, I've extended my datagrid class to provide the asc/desc feature while adding a purty little triangle in the header to indicate the direction/column the datagrid is currently sorted.  Then the Datagrid exposes a new property that tells me which way the user wants to sort, and I rebind the datagrid based on that when I hit a sortcommand.  Works incredibly great, but alas, I don't think it matters for this post.

--Michael
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11914595
are you simply asking why viewstate size increases in the second statement?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Author Comment

by:raterus
ID: 11914660
yes, and how to turn that off.  And why the viewstate doesn't increase using the first statement.
0
 
LVL 33

Author Comment

by:raterus
ID: 11914697
Lemme guess, the LiteralControls the databinding syntax is creating... :-)  If that's it, no need to tell me how to turn it off, already on it
--Michael
0
 
LVL 33

Author Comment

by:raterus
ID: 11914711
actually I know a "way" to disable the viewstate in the literalcontrols (using ItemDataBound), but if you have a better way, I'm all ears
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 2000 total points
ID: 11915266
well I guess you answered your own question;)
0
 
LVL 33

Author Comment

by:raterus
ID: 11915969
Yeah, but unfortunately I can't accept my answer and get the points..so here!
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11915985
lol thank you raterus, I wish I would have had a better one for you.

Regards,

Aeros
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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