Results 1 to 15 of 15

Thread: [RESOLVED] [2005] how to get to DropDownList in GridView Control.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Resolved [RESOLVED] [2005] how to get to DropDownList in GridView Control.

    gooday all..

    working with the DataView Control under Visual Web Developer 2005 Express.
    DataGrid is databound.
    got a template column containing a DropDownList, defined like so:
    Code:
                    <asp:TemplateField Visible="False">
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ddl2source" DataTextField="Status"
                                DataValueField="statusID">
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="ddl2source" runat="server" ConnectionString="<%$ ConnectionStrings:assetsConnectionString1 %>"
                                ProviderName="<%$ ConnectionStrings:assetsConnectionString1.ProviderName %>"
                                SelectCommand="SELECT assets.amstatus.* FROM assets.amstatus"></asp:SqlDataSource>
                        </EditItemTemplate>
    column's Visible=False till user click Edit then in the GridView1_RowEditing Event, i cgange Visible property to true like so:
    VB Code:
    1. GridView1.Columns(4).Visible = False
    2.         GridView1.Columns(5).Visible = True
    so DropDownList is availble to user to select new value for edited row. that works fine.

    i wish to show DropDownList to user only in the relevant cell of edited row..
    something like
    VB Code:
    1. GridView1.SelectedRow.Cells(4).Visible = False
    2. GridView1.SelectedRow.Cells(5).Visible = True
    or like
    VB Code:
    1. Dim mms As TableCell = New TableCell
    2. mms = GridView1.SelectedRow.Cells(4)
    3. mms.Visible=False

    alas, no go there..

    any ideas guys? possible task at all?

    thanks in advance for any help/ideas.
    Happy Friday,
    Last edited by josephine; Sep 5th, 2006 at 12:16 PM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] accessing one specific cell in GridView Control.

    In the ItemDataBound event, you can check for the row number and hide or show the corresponding items (use e.Item.FindControl()). It may be ItemDataBound or RowDataBound.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] accessing one specific cell in GridView Control.

    Quote Originally Posted by mendhak
    In the ItemDataBound event, you can check for the row number and hide or show the corresponding items (use e.Item.FindControl()). It may be ItemDataBound or RowDataBound.
    as always MendHak, tnx for a quick reply..!

    found the control, using the FindControl thingy... but unfortunately,
    sorry, no go.

    here is the code:
    VB Code:
    1. Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    2.         If e.Row.RowType = DataControlRowType.DataRow Then
    3.             Dim ddl11 As DropDownList = CType(e.Row.FindControl("ddl1"), DropDownList)
    4.         End If
    5.     End Sub
    how do i get the row number?
    how do i access items in the row?

    again, i wish to display a template "Cell" (combination of row and column).

    in the attached pics, a pic b4 edit press,and one post edit press. (using GridView1.Columns(4).Visible = False, GridView1.Columns(5).Visible = True )
    check out the Column named "STATUS",
    it displays the dropDownList all along the column, when ONLY selected row for editing, should show DropDownList.

    wataya say?
    Attached Images Attached Images   

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] accessing one specific cell in GridView Control.

    When you say 'no go', are you saying that

    Dim ddl11 As DropDownList = CType(e.Row.FindControl("ddl1"), DropDownList)

    isn't able to find the control at all?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] accessing one specific cell in GridView Control.

    Explain in detail and mention any error messages.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] accessing one specific cell in GridView Control.

    Quote Originally Posted by mendhak
    When you say 'no go', are you saying that
    Dim ddl11 As DropDownList = CType(e.Row.FindControl("ddl1"), DropDownList)
    isn't able to find the control at all?
    donno really if FindControl found the control,
    can not seem to manage in retrieving the row number, noe accessing its cells.
    donno how to show/hide corresponding items..

    y ahora?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] accessing one specific cell in GridView Control.

    Show the code you've tried using.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] accessing one specific cell in GridView Control.

    Quote Originally Posted by mendhak
    Show the code you've tried using.
    im already past this.
    have decided to just show the whole DropDownList templae column instead.(to h*ll with it)...

    could very much use your help on another issue though.
    backround:
    my Gridview has a hidden template column. containg drop down list in the <EditItemTemplate>.
    on edit row, the column with the "real data" is visible=false, and the template column offering dropdown selection is visible=true.
    user selects a value from the drop down list (dropdown has required value to update in its DataValueField).
    click the update link button and saves changes to database.

    questions:
    • 1. how do i retrieve the actual value from the DropDownList?
      2. my grid had a <DataKeyNames="infoID">, how do i incorporate this parameter into my update query? ( the whole @infoid thing )

    tnx in advance for your time in replying.
    regards,

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] DropDownList in GridView Control. and update parameter

    The GridView has an ItemCommand event. 'e' in the argument gets you the row in which the update link has been selected (assuming the update link is in the same row). You can then do e.Item.FindControl() I believe, for that dropdownlist. Convert it to DropDownList, then get its selecteditem property.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] DropDownList in GridView Control. and update parameter

    For Q2, use GridView1.DataKeyNames, which returns an array.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] DropDownList in GridView Control. and update parameter

    Quote Originally Posted by mendhak
    The GridView has an ItemCommand event. 'e' in the argument gets you the row in which the update link has been selected (assuming the update link is in the same row). You can then do e.Item.FindControl() I believe, for that dropdownlist. Convert it to DropDownList, then get its selecteditem property.

    gridview has a RowCommand event, in it 'e.CommandArgument' gives me the index of the row in which i clicked 'Edit'.
    and thats it.. i cant seem to reach the FindControl here.
    all the 'e' options have to do with the command, i.e. commnad name, commandargument, and commandsource..

    where else?

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] DropDownList in GridView Control. and update parameter

    To get the row index: Convert.ToInt32(e.CommandArgument)

    Get the row:
    Dim row as GridViewRow
    row = GridView1.Rows(rowindex)

    Now do a findcontrol, it would probably be

    row.Cells(4).FindControl("abc1")

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] DropDownList in GridView Control. and update parameter

    Quote Originally Posted by mendhak
    To get the row index: Convert.ToInt32(e.CommandArgument)
    Get the row:
    Dim row as GridViewRow
    row = GridView1.Rows(rowindex)
    Now do a findcontrol, it would probably be
    row.Cells(4).FindControl("abc1")
    1st.. really tnx for your patience here...
    done as you suggested.. unfortunately still no joy..
    my code:
    VB Code:
    1. Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    2.        
    3.         '=== NUMBER OF ROW TO BE EDITED\\\>
    4.         Dim ind As Int32
    5.         ind = e.CommandArgument
    6.         Dim row As GridViewRow
    7.         row = GridView1.Rows(ind)
    8.         Dim ddll As DropDownList = New DropDownList
    9.         ddll = CType(row.Cells(5).FindControl("ddl2"), DropDownList)
    10.         ind = ddll.SelectedValue
    11.     End Sub

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    3rd rock from the sun
    Posts
    360

    Re: [2005] done on find issue

    lemme take back my last post please ...
    Yehy!!! it works! yippy..
    problem was with "ddl2".. control not there at all cause its an EditItemTemplate and not an ItemTemplate, and i set my template column to be visible false till user clicks edit.
    a simple if GridView.Columns(5).Visible=true fixed it.

    excellent, tnx Mend.. next que (Q2 from b4... ) coming now..

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2005] how to get to DropDownList in GridView Control.

    No problem, keep them coming.

    her eyes were red and her hair was green...

Posting Permissions

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



Click Here to Expand Forum to Full Width