none
LinqDataSource + GridView = Night mare!!! RRS feed

  • Question

  • 1.
    var users = form u in UserTbl select u;

    mGridView.DataSource = ;
    mGridView.DataBind();

    Issue:

    Can't rename column header.

    Turn off autogenerateheader, and I can't get sorting.

    If I am not using a LinqDataSource, there are a lot of events that I need to handle. But at the same time, most of the event has BUG in it. Example: the Sorting event doesn't update the direction.

    2.
    Switch to LinqDataSource.

    Found out that ImageButton has bug in it. In most cases Click event will trigger twice. It was reported in 2006, but this problem never get fix until 2009.

    Have to work around this issue with <TemplateField>

    3.
    LinqDataSource.Where = "(Privilege & @Priv) > 0";

    Will never work. Can't figure out what had gone wrong yet. (in my another mail)

    4.
    Once I touched the Where property, the LinqDataSource loses it DataKeys, can there is no way for me to find out what the user has clicked :(

     

    I really don't know how much problem I will face, but LinqDataSource + GridView is really something I will avoid next time..... :(

    Sunday, November 8, 2009 5:28 AM

All replies

  • Hi Chui, I'm currently going down your list trying to figure out what can help in each of your bullet points.

    1. According to this article , the GridView delegates to its DataSource to perform the sorting. If there is no DataSource bound, then the GridView's sorting behavior will be erratic. (e.g. the SortDirection in the Sorting event will always be Ascending).

    2. I found some forum posts about this, and there appear to be a few workarounds , although they seem painful.

    3. Is this a bitwise AND operation? If so, I don't believe this is supported by the LinqDataSource.

    4. Is this for SelectedIndexChanged or for updating/deleting? If it's for updating or deleting you can handle events on the LinqDataSource (Updating and Deleting, respectively) to gain access to the object being changed. If it's for SelectedIndexChanged, assuming you have ViewState enabled you can index into the GridView's Rows collection to find the values of the row that was selected.

    Sorry if these answers are not exactly what you're looking for. You might find better answers if you ask on the ASP.NET forums .

    Thanks,
    David
    Blog - http://blogs.rev-net.com/ddewinter/ Twitter - @ddewinter
    Monday, November 9, 2009 2:46 AM
    Answerer
  • David,

    Thanks for the answer.

    No 3 is really a pain. I can't filter user by their privileges.

    LINQ does support the Bitwise AND oprator, just that the LinqDataSource doesn't. And I am stucked with my assignment now :(

    Hope some one can really give me a clue how to proceed form here.



    No 4. I figured out a solution myself. In the Command triggered, I manage to put the object ID into the CommanArgument instead of the RowIndex found almost all example in the web.

    CommandArgument= '<%# DataBinder.Eval(((GridViewRow)Container).DataItem, "ID") %>'

     

     

     

    Monday, November 9, 2009 8:50 AM
  • For Issue #3


    I think I know what caused this BUG.

    LinqDataSource wrongly interpreted the '&' operator as the string concatenation sign in VB.

    But at the same time correctly interpreted the ‘AND’ operator as logical AND.

    So, question now is, is there any other way to represent a bitwise AND operator?

    Tuesday, November 10, 2009 12:24 PM