Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Data displaying in datagrid as dynamically..

Data displaying in datagrid as dynamically..

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpquestion
18 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Prabs frm PGP

    Thanks for ur suggestion., I did that one., How can we retrieve and display the data to that appropriate image button & label box..? Prabu.T

    _ Offline
    _ Offline
    _AK_
    wrote on last edited by
    #4

    You can use onitemdatabound event for that purpose it executes for each an every row of the datagrid. In that event you just have to find the control and assign the values.

    Best Regards, Apurva Kaushal

    P 1 Reply Last reply
    0
    • _ _AK_

      You can use onitemdatabound event for that purpose it executes for each an every row of the datagrid. In that event you just have to find the control and assign the values.

      Best Regards, Apurva Kaushal

      P Offline
      P Offline
      Prabs frm PGP
      wrote on last edited by
      #5

      Hi! Apurva! I am a newer., Can u give me some sample coding.. How can we using that findcontrol method?

      _ 1 Reply Last reply
      0
      • P Prabs frm PGP

        Hi! Apurva! I am a newer., Can u give me some sample coding.. How can we using that findcontrol method?

        _ Offline
        _ Offline
        _AK_
        wrote on last edited by
        #6

        here is the sample code for itemdatabound event: public void dg_ItemBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { Label lbl = (Label)e.Item.FindControl("lblName"); lbl.Text = "Apurva"; } }

        Best Regards, Apurva Kaushal

        P 1 Reply Last reply
        0
        • _ _AK_

          here is the sample code for itemdatabound event: public void dg_ItemBound(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { Label lbl = (Label)e.Item.FindControl("lblName"); lbl.Text = "Apurva"; } }

          Best Regards, Apurva Kaushal

          P Offline
          P Offline
          Prabs frm PGP
          wrote on last edited by
          #7

          Hi! I tried that one., but The DataGrid Control is not displaying., We have to Bind the Datagrid na.... How can we do that one..? Prabu.T

          _ 1 Reply Last reply
          0
          • P Prabs frm PGP

            Hi! I tried that one., but The DataGrid Control is not displaying., We have to Bind the Datagrid na.... How can we do that one..? Prabu.T

            _ Offline
            _ Offline
            _AK_
            wrote on last edited by
            #8

            For that first you need to get the data from the database and then assign the datasouse property and then bind the datagrid by calling the method databind. This is the sample code to bind the datagrid: SqlConnection conn = new SqlConnection("Your connection string"); SqlCommand com = new SqlCommand("Select * from emp", conn); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); DataGrid1.DataSource = ds; DataGrid1.DataBind();

            Best Regards, Apurva Kaushal

            P 1 Reply Last reply
            0
            • _ _AK_

              For that first you need to get the data from the database and then assign the datasouse property and then bind the datagrid by calling the method databind. This is the sample code to bind the datagrid: SqlConnection conn = new SqlConnection("Your connection string"); SqlCommand com = new SqlCommand("Select * from emp", conn); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); DataGrid1.DataSource = ds; DataGrid1.DataBind();

              Best Regards, Apurva Kaushal

              P Offline
              P Offline
              Prabs frm PGP
              wrote on last edited by
              #9

              Hi! Thanks i got datagrid with the Labelbox control it displays what i gave in that control's text ie., if i gave lbl.text="Apurva" it shows this one but i i need the value frm DB.. Prabu.T

              _ P 2 Replies Last reply
              0
              • P Prabs frm PGP

                Hi! Thanks i got datagrid with the Labelbox control it displays what i gave in that control's text ie., if i gave lbl.text="Apurva" it shows this one but i i need the value frm DB.. Prabu.T

                _ Offline
                _ Offline
                _AK_
                wrote on last edited by
                #10

                For this you need to fetch the data from the database and then assign. If you are having the data in the same table which you have bind to the datagrid then with the help of datarowview you can access the data and then can assign the data to the control in ontemdatabound event. like this: DataRowView drv = (DataRowView)e.Item.DataItem; lbl.Text=drv[0].ToString(); -- modified at 4:44 Wednesday 9th August, 2006

                Best Regards, Apurva Kaushal

                1 Reply Last reply
                0
                • P Prabs frm PGP

                  Hi! Thanks i got datagrid with the Labelbox control it displays what i gave in that control's text ie., if i gave lbl.text="Apurva" it shows this one but i i need the value frm DB.. Prabu.T

                  P Offline
                  P Offline
                  Prabs frm PGP
                  wrote on last edited by
                  #11

                  Hi nice yar., I got that one also., but if i add another one control with that one., thats a imagebutton control., i did what u gave for that label box i did kike that only ImageButton img =(ImageButton)e.Item.FindControl("imgbtnModel"); img.ImageUrl= "E:\rose.jpg"; first for ex: i gave like this but for this also i hv to retrieve the url frm DB., k., i vl do that one used that datarowview., but wat s the error in the above one..? T.Prabu

                  _ P 3 Replies Last reply
                  0
                  • P Prabs frm PGP

                    Hi nice yar., I got that one also., but if i add another one control with that one., thats a imagebutton control., i did what u gave for that label box i did kike that only ImageButton img =(ImageButton)e.Item.FindControl("imgbtnModel"); img.ImageUrl= "E:\rose.jpg"; first for ex: i gave like this but for this also i hv to retrieve the url frm DB., k., i vl do that one used that datarowview., but wat s the error in the above one..? T.Prabu

                    _ Offline
                    _ Offline
                    _AK_
                    wrote on last edited by
                    #12

                    Exactly dude.... :)

                    Best Regards, Apurva Kaushal

                    1 Reply Last reply
                    0
                    • P Prabs frm PGP

                      Hi nice yar., I got that one also., but if i add another one control with that one., thats a imagebutton control., i did what u gave for that label box i did kike that only ImageButton img =(ImageButton)e.Item.FindControl("imgbtnModel"); img.ImageUrl= "E:\rose.jpg"; first for ex: i gave like this but for this also i hv to retrieve the url frm DB., k., i vl do that one used that datarowview., but wat s the error in the above one..? T.Prabu

                      P Offline
                      P Offline
                      Prabs frm PGP
                      wrote on last edited by
                      #13

                      Hi Apurava., I got that image also., everything is fine., Last one: If i clicks that image butoon it has to go some other page and displays the details abt that page., how can v do this one..? Prabu.T

                      _ 1 Reply Last reply
                      0
                      • P Prabs frm PGP

                        Hi nice yar., I got that one also., but if i add another one control with that one., thats a imagebutton control., i did what u gave for that label box i did kike that only ImageButton img =(ImageButton)e.Item.FindControl("imgbtnModel"); img.ImageUrl= "E:\rose.jpg"; first for ex: i gave like this but for this also i hv to retrieve the url frm DB., k., i vl do that one used that datarowview., but wat s the error in the above one..? T.Prabu

                        P Offline
                        P Offline
                        Prabs frm PGP
                        wrote on last edited by
                        #14

                        Hi Apurava., I got that image also., everything is fine., Last one: If i clicks that image butoon it has to go some other page and displays the details abt that page., how can v do this one..? and during dynamic retrieval how can v achieve the paging on datagrid? Prabu.T

                        _ 1 Reply Last reply
                        0
                        • P Prabs frm PGP

                          Hi Apurava., I got that image also., everything is fine., Last one: If i clicks that image butoon it has to go some other page and displays the details abt that page., how can v do this one..? Prabu.T

                          _ Offline
                          _ Offline
                          _AK_
                          wrote on last edited by
                          #15

                          Two ways are there either you can put that in anchor tag and give href property or you can handle the click event of the imagebutton in the itemcommand event of the datagrid.

                          Best Regards, Apurva Kaushal

                          1 Reply Last reply
                          0
                          • P Prabs frm PGP

                            Hi Apurava., I got that image also., everything is fine., Last one: If i clicks that image butoon it has to go some other page and displays the details abt that page., how can v do this one..? and during dynamic retrieval how can v achieve the paging on datagrid? Prabu.T

                            _ Offline
                            _ Offline
                            _AK_
                            wrote on last edited by
                            #16

                            for datagrid paging you can take help of this site. It is having so many good articles on datagrid. www.datagridgirl.com :)

                            Best Regards, Apurva Kaushal

                            P 1 Reply Last reply
                            0
                            • _ _AK_

                              for datagrid paging you can take help of this site. It is having so many good articles on datagrid. www.datagridgirl.com :)

                              Best Regards, Apurva Kaushal

                              P Offline
                              P Offline
                              Prabs frm PGP
                              wrote on last edited by
                              #17

                              Hi Apurva., Today only i registered to this Forum., and its my first question very nice and patient answer from ur side., Thanks yaar.., Prabu.T

                              _ 1 Reply Last reply
                              0
                              • P Prabs frm PGP

                                Hi Apurva., Today only i registered to this Forum., and its my first question very nice and patient answer from ur side., Thanks yaar.., Prabu.T

                                _ Offline
                                _ Offline
                                _AK_
                                wrote on last edited by
                                #18

                                always welcome... :)

                                Best Regards, Apurva Kaushal

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups