Probably the simplest thing in the world...



  • Im having a problem doing anything at the moment, just cant think!

    Basically the problem that I have right now is that I have a gridView on a page, the grid view has a template column which allows the user to set the status of the record being displayed to true, this then moves the record out of the current gridview (as it only displays records where the active flag is false) This is not the problem. The problem is that I now have to add a drop down list to the gridview to display the type of record that is being displayed (Again this is fine), but the final bit is that when the user clicks on the activate linkButton the record should be set active and have its type updated based on the users selection from the dropdown list, I cant work out how in the itemCommang event to get access to the value of the drop down list for the row, everything I try fails.

    Im sure that this is just because Im tired and if I come back to it tommorow it will be obvious, but until that happens any ideas?

     

    Thanks



  •  It might be helpfull if you tell us which version of which programming language, framework etc. you are using. A screenshot of what you are trying to accomplish probably wouldn't hurt either.



  • moon on a stick... I dunno..

     .net 2.0
    C#

    I basically have the following Grid view:

    Date Added Title User Name Active Edited Type  
    22/02/2008 02:08:00 Davids Test Article! testArticle <INPUT id=gvPendingFinal__ctl2__ctl0 disabled type=checkbox CHECKED name=gvPendingFinal:_ctl2:_ctl0> <INPUT id=gvPendingFinal__ctl2__ctl1 disabled type=checkbox name=gvPendingFinal:_ctl2:_ctl1> <SELECT language=javascript class=BodyText id=gvPendingFinal__ctl2_DropDownList1 onchange="javascript:setTimeout('__doPostBack(\'gvPendingFinal$_ctl2$DropDownList1\',\'\')', 0)" name=gvPendingFinal:_ctl2:DropDownList1> <OPTION value=0 selected>Features</OPTION> <OPTION value=1>People</OPTION></SELECT> Activate
    22/02/2008 02:13:00 Davids Test Article! testArticle <INPUT id=gvPendingFinal__ctl3__ctl0 disabled type=checkbox CHECKED name=gvPendingFinal:_ctl3:_ctl0> <INPUT id=gvPendingFinal__ctl3__ctl1 disabled type=checkbox name=gvPendingFinal:_ctl3:_ctl1> <SELECT language=javascript class=BodyText id=gvPendingFinal__ctl3_DropDownList1 onchange="javascript:setTimeout('__doPostBack(\'gvPendingFinal$_ctl3$DropDownList1\',\'\')', 0)" name=gvPendingFinal:_ctl3:DropDownList1> <OPTION value=0>Features</OPTION> <OPTION value=1 selected>People</OPTION></SELECT> Activate
     
    When you click activate it sets a flag in the database that says the article is active, this is fine, what I want to do is also update the type field, just cant get access to the value of the drop down list no matter what I try...
     
    Thanks
     
    David
     
    [EDIT] - you will have to imagine that where it says Features people in the above that these are in a drop down list...


    1. Use an OnCommand event handler on the activate button/link/checkbox/etc. and set the row index of the grid view as the CommandArgument property of said button/link/checkbox/etc. for each row when databinding.
    2. When OnCommand fires and executes the event handler, in addition to setting the article as active in the database, retrieve the row index from said CommandArgument.
    3. Use the row index to retrieve the proper datagrid row and use the FindControl() method on that row to obtain references to the dropdown list controls.
    4. Alter the SelectedValue property for the dropdown lists.


  • Thanks for that,

     Im going to have a bash at it later, Im not seeing how I will get the Id of the row so that I can use it to update the database... I Guess Ill get that sorted when I start working on it again.

     

    Thanks



  • @wonkoTheSane said:

    Thanks for that,

     Im going to have a bash at it later, Im not seeing how I will get the Id of the row so that I can use it to update the database... I Guess Ill get that sorted when I start working on it again.

     

    Thanks

     

     

    I assume you mean the ID of the recordset row?  There is a gridview property(and I forget the exact name but if you google "gridview row ID" or something to the like you should find it) to set a column in each of your gridview rows to the ID property.  So when the user clicks, you can lookup the id in that column and do your update.   It's on the gridview level and it's something like "IDColumn='<Name of Column>'"



  • Hi, I got all of this working last night, thanks for the help, I ended up using the dataKeys collection against the gridView using this and the current gridviewRow (Which is now passed as the command argument of the update button) using both of these values I can lookup the value of the drp down on the row that Im working with, and update the database.

    Thanks again for the help, Saved me a load of time!

     



  • I usually use the RowCommand event, check the e.CommandName and make sure that it's the command I want (not "Page"), then do something like this:

    Dim row As GridViewRow = Me.grd.Rows(CInt(e.CommandArgument))
    Dim ddl As DropDownList = CType(item.Cells(0).Controls(0), DropDownList)

    That's assuming your dropdown list is in the first column (cells(0)) by its lonesome (controls(0)).  Then you can use your dropdownlist like you wants.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.