Link to home
Start Free TrialLog in
Avatar of ajmac-b
ajmac-bFlag for Australia

asked on

How to rebind bound columns in a datagrid after a data rebind

I have a datagrid on as aspx page. The datagrid has a bound column so the user can drill down using a key field.
The user has available a couple of radio buttons which trigger the grid to be rebound using filtered data. When the grid redisplays with the new data, the bound column row index structure has not been updated. Clicking on, say, the first row returns the key for the ORIGINAL first row, rather than the filtered first row.
Can anyone help as to how to overcome this problem.
Thanks in advance
Avatar of mmarinov
mmarinov

when you use bound columns it is matter how do you bound it ( the information that you give to it )
so when in the first time you have for example for the 3rd row index 3 and in the rebound datagrid you have again 3 instead of 5, then you just give it 3 instead of 5

you have to check how do you feel the column that returns data in this column, or you can paste the code so the EE can help you

B..M
I fought this same problem for two days ... I figured out why it happens but I don't remember all of the details.  I wish I could provide you more information but I can tell you that you probably will not find a non-spaghetti way around this problem. :(
Avatar of ajmac-b

ASKER

Thanks for your replies - I hope the solution is not as complicated as you say, SirCaleb.
The code used to bind the grid (DG) is as follows. I think its pretty standard:

Public Function fillDG(ByVal sid As String, ByVal SortField As String, ByVal optnum As Integer)
        Dim sortorder As String
        Dim sql As String
        Dim sf As String
        Dim cmd As SqlCommand
        Dim rdr As SqlDataReader
        sf = Session("SortField")
        sortorder = Session("SortOrder")
        Select Case optnum
            Case 1  'Registered
                sql = "Select * from [ccq_Claims2] where [StoreID] like '" & sid & "' and [Approved] = 0"
            Case 2
                sql = "Select * from [ccq_Claims2] where [StoreID] like '" & sid & "' and [Approved] > 1"
            Case Else
                sql = "Select * from [ccq_claims2] where [StoreID] like '" & sid
        End Select
        sConWEBSERVER.Open()  'Globally defined conenction string
        cmd = New SqlCommand(sql, sConWEBSERVER)
        rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        dg.DataSource = rdr
        dg.DataBind()
        sConWEBSERVER.Close()
    End Function
this function is fine to me and i don't see any problem, but do you have ItemDataBound event or do something with that index bound column
what actually is displaied in it ? may be will be easy if you can post some of your html and if you have some events to your datagrid

B..M
Avatar of ajmac-b

ASKER

I eventually gave up on a bound Column (ButtonColumn) as the replies here and elsewhere were not very encouraging. I used Hyperlinkcolumns instead.
If anyone else has the same problem - the Hyperlink key solution works fine.
To solve the problem, in the datagrid properties page, open the columns collection
and add a hyperlink button. Set the TextField to the data field needed, then specify the url (In my case this was 'Claims.aspx'), and the Display to the same thing.
You also have to set the URL Format string to something like:  'Claims.aspx?ID={0}

The objective was to pass a key number to another page when the button was clicked, so I decided that using a request.querystring approach might be easier.

Thanks guys for the encouragement. What do I do with the points?
because you find a solution to your problem by yourself you don't have award points
if you think that some of answers are helped to you to find the solution you can award it/them with a lower than A Grade ( for grades look here https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP.NET/help.jsp#hi73 )

if you don't want to award answers, you have to post a question in the Community Support to delete your question and return your points

B..M
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial