gridview...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepk84
    New Member
    • Oct 2006
    • 97

    gridview...

    hi all...
    can anyone tell me how can i add columns to a gridview dynamically?
    not at d end but in between two columns whenever needed..
    please help...
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Are you using Visual Studio? This is the easiest way, add a column and place it in the order that you want from the property builder.

    For greater flexibility and design options, I often use DataLists. I place the fields where I want and usually have an html table mimic the DataGrid look.

    Hope that this helps.

    Comment

    • sandeepk84
      New Member
      • Oct 2006
      • 97

      #3
      Originally posted by kenobewan
      Are you using Visual Studio? This is the easiest way, add a column and place it in the order that you want from the property builder.

      For greater flexibility and design options, I often use DataLists. I place the fields where I want and usually have an html table mimic the DataGrid look.

      Hope that this helps.
      Thanks a lot...yeah am using Visual Studio...
      I have to add columns at runtime..i could add col. using pty builder at design time only...I have to have some select buttons also in the existing columns...that' s
      y i used gridview...is there any function to add columns dynamically?
      like it will allow us to tell the col index where to add d new one?
      thanks and regards...
      sand...

      Comment

      • vinaykeshav
        New Member
        • Dec 2006
        • 25

        #4
        how are you binding data to ur datagrid is it using list ?
        and y do u want to create column at runtime...

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Originally posted by sandeepk84
          Thanks a lot...yeah am using Visual Studio...
          I have to add columns at runtime..i could add col. using pty builder at design time only...I have to have some select buttons also in the existing columns...that' s
          y i used gridview...is there any function to add columns dynamically?
          like it will allow us to tell the col index where to add d new one?
          thanks and regards...
          sand...
          I was thinking that you create the column at design time and populate it at runtime - I believe that you could also hide it at runtime if you wanted. Your best option then is to create the whole datagrid at runtime and populate it then.

          Hope this helps.

          Comment

          • sandeepk84
            New Member
            • Oct 2006
            • 97

            #6
            Originally posted by kenobewan
            I was thinking that you create the column at design time and populate it at runtime - I believe that you could also hide it at runtime if you wanted. Your best option then is to create the whole datagrid at runtime and populate it then.

            Hope this helps.
            thanks...
            but there comes d pblm again...the grid will have columns based only on the input from another form in the site...so at design time i can't create columns or i can't know how many cols will b there...no. of cols increases as per d o/p frm d
            other form..
            and even if i create d whole grid at runtime i can't say where it should b displayed..ther e r many other objects in the page..both html and aspx...
            thanks and regards...
            sand...

            Comment

            • sandeepk84
              New Member
              • Oct 2006
              • 97

              #7
              Originally posted by vinaykeshav
              how are you binding data to ur datagrid is it using list ?
              and y do u want to create column at runtime...
              am using classes like sqlcommand,sqlc onnection, sqldatareader etc...
              am populating d grid by specifying the datasource property of
              sqldatareader object...so data frm d database comes to d grid directly...
              but i can't know how many cols will b there in the datagrid..
              some i know..and those r designed using boundfield..
              and some new cols come at runtime..the no. is not fixed...
              depends upon data frm another form....
              thanks and regards...
              sand...

              Comment

              • vinaykeshav
                New Member
                • Dec 2006
                • 25

                #8
                as i read the solutions from others ..
                it seems that u cant decide the no of cols at design time.
                if u need to use a single datagrid and when ur bindind datagrid u cant add cols at runtime...
                so the solution is that the datasource should b having the constant no of cols
                before binding... so at some case if for example a col name appears for some case and doesnt for others then at the case where it doesnt appear u should manually add col and keep it dummy so that it doesnt generate runtime binding error and at databound event u can make it visible if u dont need...

                Originally posted by sandeepk84
                am using classes like sqlcommand,sqlc onnection, sqldatareader etc...
                am populating d grid by specifying the datasource property of
                sqldatareader object...so data frm d database comes to d grid directly...
                but i can't know how many cols will b there in the datagrid..
                some i know..and those r designed using boundfield..
                and some new cols come at runtime..the no. is not fixed...
                depends upon data frm another form....
                thanks and regards...
                sand...

                Comment

                • sandeepk84
                  New Member
                  • Oct 2006
                  • 97

                  #9
                  Originally posted by vinaykeshav
                  as i read the solutions from others ..
                  it seems that u cant decide the no of cols at design time.
                  if u need to use a single datagrid and when ur bindind datagrid u cant add cols at runtime...
                  so the solution is that the datasource should b having the constant no of cols
                  before binding... so at some case if for example a col name appears for some case and doesnt for others then at the case where it doesnt appear u should manually add col and keep it dummy so that it doesnt generate runtime binding error and at databound event u can make it visible if u dont need...
                  thanks a lot...
                  i was trying to have the datasource with all d cols...so d cols r not to b added
                  to d grid anymore...was thinking of adding some columns to the table using alter
                  command...
                  thanks and regards..
                  sand....

                  Comment

                  Working...