Adding blank rows to Gridview...

Last post 02-28-2008 11:38 AM by Coleen. 14 replies.

Sort Posts:

  • Adding blank rows to Gridview...

    02-25-2008, 3:20 PM
    • Member
      537 point Member
    • Coleen
    • Member since 09-20-2006, 4:08 PM
    • Posts 528

    Okay - I just had an idea about my adding blank rows problem...please let me know if anyone knows if this is feasible:

    The GridView will have some dropdownlists that will be populated by connecting to a different ObjectDataSource, and depending on what criteria is selected in DDL's that are separate from the gridview (but must be selected before the girdview will allow data entry) there are some columns in the Gridview that should automatically populate with data (such as the State they're in.)  Since I will have this "data" to populate the Gridview with to start with - is there a way to then populate the gridview with blank rows in all the other columns?  Did this make sense?  Thanks again for any help/suggestions - I really appreciate it.

    Coleen
    "We Develop Webs"
  • Re: Adding blank rows to Gridview...

    02-25-2008, 4:54 PM
    • Member
      252 point Member
    • Tim K
    • Member since 02-25-2008, 3:43 PM
    • Posts 49

    Create a DataTable with the correct schema for the GridView.

    Add rows to it such that the default values are supplied and where you want blanks, just add string.Empty or DBNull.Value.

  • Re: Adding blank rows to Gridview...

    02-25-2008, 6:18 PM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    Not understanding clearly... You want to partially populate the row but also have the user complete blank fields?

    I am not anti social, am just not user friendly
  • Re: Adding blank rows to Gridview...

    02-25-2008, 6:43 PM
    • All-Star
      63,048 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,311
    • TrustedFriends-MVPs

     >please let me know if anyone knows if this is feasible

    A  better way would be to use a dedicated form for adding a new record. This is much easier understood by users and is much simpler to program.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Adding blank rows to Gridview...

    02-25-2008, 7:31 PM
    • Member
      537 point Member
    • Coleen
    • Member since 09-20-2006, 4:08 PM
    • Posts 528

    Sorry - a little history is in order for you to understand what I'm faced with.  First, we don’t use an SQL DB to store our data - it is a DB2 database, which we connect to through an RPC call to a COBOL program which in turn does the actual CRUD and passes the info back to me via a string that we interpret using a function to parse the string sent from DB2.  It's a pain in the - yeah!
    Second, we are currently using a third party control grid which we are not renewing the license to so we have to convert it to use the GridView - hence the issue with using the GridView to enter data in.  This is an existing web application that I have to update to have the same functionality as the 3rd party control. We use one screen that has some selections in separate DDL's to set the criteria for what should be pre-populated in the Gridview, but otherwise the user will be filling in the rows as in a data entry form.  The users want it as a Spreadsheet type form, and since all the code to d the validation is already written (it just has to be "fit" to the gridview, which is fairly simple - other than the issue of starting with blank rows...)
    Does this make a little more sense? Please see this thread: http://forums.asp.net/t/1220690.aspx for a complete reference on what I'm doing/trying to do.  Thanks for everyone's help. 
    "Not understanding clearly... You want to partially populate the row but also have the user complete blank fields?" - Yes - exactly.  Some fields are supposed to be pre-populated from selections that the user makes before the Gridview displays...
        

     

    Coleen
    "We Develop Webs"
  • Re: Adding blank rows to Gridview...

    02-26-2008, 3:05 AM
    • All-Star
      63,048 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,311
    • TrustedFriends-MVPs

     >Does this make a little more sense?

    It does make more sense now!

    I would suspect that you have not put so many columns of data that when you switch to edit, there is enough slack space horizontally to avoid a squashing effect.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Adding blank rows to Gridview...

    02-26-2008, 11:04 AM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    Sorry Coleen,

    I am a little dense,  So it sounds to me like all you need to do is an update to the rows??  If these rows are pre-populated and user needs to complete data entry then

    GridView1.EditIndex = [rowindex]
    GridView1.Databind()

    Where [rowindex] represents the selected row.  Of course that assuming that you are manually performing your edits which in your case I think it is.

    I am not anti social, am just not user friendly
  • Re: Adding blank rows to Gridview...

    02-26-2008, 11:22 AM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    One more thingBig Smile

    Assuming you do not want to use the gridview command buttons you can do what I said before

    You will need to keep track of rowindex but two regular buttons one for edit the other for update.  in click event for edit

    as I stated before

    In the click event for update

    ' do something for updating
    MyUpdateFunction()

    ' the next two lines is just to get the grid back to normal view mode
    Gridview1.EditIndex = -1
    Gridview1.DataBind()

     

    I am not anti social, am just not user friendly
  • Re: Adding blank rows to Gridview...

    02-26-2008, 12:01 PM
    • Member
      537 point Member
    • Coleen
    • Member since 09-20-2006, 4:08 PM
    • Posts 528

    Well - yes & no on the Editing.  I guess that's where I need a little help with this.  I need the Gridview to open with up to 10 empty rows - except for the 3 or 4 dropdownlists that will be available (and 2 of the 3 MAY be pre-populated depending on criteria selected from other DDL's beofre the Gridview is rendeered) - but the issue I have is that we don't store empty rows in the DB so even though I am going to be connecting the Gridview DDL's to a different ODS, I am still wondering how to get my intitial empty rows to display... thanks for your help Smile

     

    Coleen
    "We Develop Webs"
  • Re: Adding blank rows to Gridview...

    02-26-2008, 1:24 PM
    • Member
      148 point Member
    • jekerry
    • Member since 08-23-2006, 8:37 PM
    • Posts 72

    Any reason this has to be a Gridview?  Sounds like a repeater would be very easy to do this way.  Just build the table with the empty text boxes for the "new" data and save what you want to the database when they hit a submit button?  What is the gridview providing?

     jekerry

    jekerry
  • Re: Adding blank rows to Gridview...

    02-26-2008, 2:40 PM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    Coleen

    Now when you get the grid to render rows are you using Data Source control or you doing this using the Datasource property of the Gridview?

    Something like

    Gridview1.DataSource = YourProcedure()  ' This may return a datatable of dataset

    Gridview1.Databind()

    In a situation such as this we can use the datasource to create a table that we can insert or add blanks rows in fact in your case both then we would have to persist them using session, cache or viewstate in case of a postback or twoBig Smile

    I have answered this kind of question before on this forum so it would be entirely posible to insert as many blank row around the data that came back from the database then have a button to commit to the database at which point you would destroy the cached items.

    typically you can create a datatable

    dim dt as datatable = ctype(gridview1.datasource, datatable)

    C#

    datatable dt = (datatable)gridview1.datasource;

    To insert it would simply be a matter of

    dim rw as datatrow = dt.newrow

    do sothing with the columns with are index rw(0), rw(1) etc

    then

    dt.add(rw) or dt.insert(rw, indx)  where indx =insert  at

    Do you get the picture?

    You would then have to save it to a persistent source

    Session("myDataTabl") = dt

    to read it out you would do

    dim dt as datatable = ctype(Session("myDataTabl"), datatable)

    and you would have to create a bindgrid routing that would handle this on postback.

     

    If you like I can send you a complete piece of code that does this.  But if you post your page I can taylor it as close as possible to what you have.

    Your choice Smile

    Let us know

     

     

    I am not anti social, am just not user friendly
  • Re: Adding blank rows to Gridview...

    02-27-2008, 2:38 PM
    • Member
      537 point Member
    • Coleen
    • Member since 09-20-2006, 4:08 PM
    • Posts 528
    Jekerry - Good question.  Okay - first I have never used a repeater (but am definitely open to trying it) and second - no it doesn't "have" to be a GrdiView - it's just that they want a SpreadSheet type layout. 
     
    Aamador - at the point I was at (I had to switch to another project for a couple of days) I wasn't connecting to any data source - yet.  After discussing this issue with the "powers that be" here, we decided to forget trying to make the GridView work for this and I will be creating a dataentry form now.
     
    Jekerry - do you have a suggestion or link to a place where I can find out how to use the repeater to do this?  this sounds like an ideal solution for the problem...
     
    Thanks very much to both of you for your help! Smile
     
    Coleen
    "We Develop Webs"
  • Re: Adding blank rows to Gridview...

    02-27-2008, 3:38 PM
    Answer
    • Member
      148 point Member
    • jekerry
    • Member since 08-23-2006, 8:37 PM
    • Posts 72

    There is tons of info on the web about repeaters. They are good to know about since they do not have the overhead of a gridview and you have lots of control over the way they look.  One of my favorite controls for larger datasets.

     Here's a site to get you started

    http://msdn.microsoft.com/msdnmag/issues/05/06/CuttingEdge/

    jekerry

    jekerry
  • Re: Adding blank rows to Gridview...

    02-27-2008, 4:20 PM
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    actually that's a good decision.  While it is doable it is not necessarily a good idea to do all that with the gridview. 

    Good luck

    I am not anti social, am just not user friendly
  • Re: Adding blank rows to Gridview...

    02-28-2008, 11:38 AM
    • Member
      537 point Member
    • Coleen
    • Member since 09-20-2006, 4:08 PM
    • Posts 528

    Thank you both so much!  Jekerry, thank you for the link - I am delving into this with both feet (I hope I don't drownWink )

     

    Coleen
    "We Develop Webs"
Page 1 of 1 (15 items)