+ Reply to Thread
Results 1 to 4 of 4

Thread: Check checkbox in datagrid

  1. #1
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Check checkbox in datagrid

    I have this db structure
    tblcategorymaster
    -Category_Id
    -Category_Name

    tblitemmaster
    -Item_Id
    -Category_Id
    -Item_Name

    tblstoremaster
    -Store_Id
    -Store_Name.....

    tblstoreitemdetails
    -Store_Id
    -Item_Id

    So i now need to show on a page where first store will be selected, then category will be selected and then i will show items on that category in datagrid. I also need to show a checkbox in front of each item, and it will be checked/uncheked if that particular item is present in that store.

    So now i first load the datagrid with items in that category.
    Then to check the checkboxes, i check in database for that item in that store in datagrid's ItemDataBound event and check if there.

    Now my question is can i do it both things in one way/call to db??

    VB.NET 2005
    MySql 5.0

    Thanx

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Sure, in the query that populates the datagrid with the category information, have it also return a bit field indicating if the item in present in the store.

    I believe you can then bind this field to the checkbox.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by Wolffy View Post
    Sure, in the query that populates the datagrid with the category information, have it also return a bit field indicating if the item in present in the store.

    I believe you can then bind this field to the checkbox.
    Hmm, i was also thinking of that........... let me see if i can write that query

  4. #4
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by micky View Post
    Hmm, i was also thinking of that........... let me see if i can write that query
    Ok, i got it.
    Posting my existing working code
    added this line in datagrid in .aspx file
    Code:
    <asp:BoundColumn Visible="False" DataField="bPresent" ReadOnly="True"></asp:BoundColumn>
    
    Then this query to load the datagrid
    Code:
    Dim strSQL As String = "Select Count(SI.Item_Id) as bPresent, I.Item_Id, I.Item_Name, I.Item_Price From tblitemmaster as I " & _
        "Left Join tblstoreitemdetails as SI on I.Item_Id=SI.Item_Id and SI.Store_Id=@StoreId " & _
        "Where I.Category_Id=@CategoryId Group By I.Item_Id"
    
    Then in datagrid's item data bound event to check the checkbox
    Code:
    Protected Sub dgItem_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItem.ItemDataBound
        If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
            Dim cb As CheckBox = e.Item.Cells(4).Controls(1)
    
            Dim intRecord As Integer = e.Item.Cells(5).Text.ToString
            If intRecord = 1 Then
                cb.Checked = True
            Else
                cb.Checked = False
            End If
        End If
    End Sub
    

+ Reply to Thread

Similar Threads

  1. Asp datagrid?
    By Centurion in forum ASP Development
    Replies: 1
    Last Post: June 11th, 2009, 07:12 AM
  2. Show records in datagrid and delete any with paging
    By micky in forum .NET Development
    Replies: 19
    Last Post: March 19th, 2009, 04:51 AM
  3. How do I check the tag of a child?
    By bryceowen in forum JavaScript Programming
    Replies: 4
    Last Post: February 19th, 2009, 02:01 PM
  4. Add a link text in Footer in datagrid??
    By micky in forum .NET Development
    Replies: 2
    Last Post: December 20th, 2008, 04:23 AM
  5. show datagrid even if empty
    By micky in forum .NET Development
    Replies: 3
    Last Post: December 9th, 2008, 08:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO