|
-
Sep 1st, 2006, 05:26 AM
#1
Thread Starter
Hyperactive Member
[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:
GridView1.Columns(4).Visible = False
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:
GridView1.SelectedRow.Cells(4).Visible = False
GridView1.SelectedRow.Cells(5).Visible = True
or like
VB Code:
Dim mms As TableCell = New TableCell
mms = GridView1.SelectedRow.Cells(4)
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.
-
Sep 1st, 2006, 05:34 AM
#2
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.
-
Sep 1st, 2006, 07:33 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] accessing one specific cell in GridView Control.
 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:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl11 As DropDownList = CType(e.Row.FindControl("ddl1"), DropDownList)
End If
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?
-
Sep 1st, 2006, 11:45 AM
#4
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?
-
Sep 1st, 2006, 11:45 AM
#5
Re: [2005] accessing one specific cell in GridView Control.
Explain in detail and mention any error messages.
-
Sep 4th, 2006, 05:18 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] accessing one specific cell in GridView Control.
 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?
-
Sep 4th, 2006, 08:17 AM
#7
Re: [2005] accessing one specific cell in GridView Control.
Show the code you've tried using.
-
Sep 4th, 2006, 10:11 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] accessing one specific cell in GridView Control.
 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,
-
Sep 5th, 2006, 05:53 AM
#9
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.
-
Sep 5th, 2006, 05:54 AM
#10
Re: [2005] DropDownList in GridView Control. and update parameter
For Q2, use GridView1.DataKeyNames, which returns an array.
-
Sep 5th, 2006, 10:47 AM
#11
Thread Starter
Hyperactive Member
Re: [2005] DropDownList in GridView Control. and update parameter
 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?
-
Sep 5th, 2006, 10:51 AM
#12
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")
-
Sep 5th, 2006, 11:50 AM
#13
Thread Starter
Hyperactive Member
Re: [2005] DropDownList in GridView Control. and update parameter
 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:
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
'=== NUMBER OF ROW TO BE EDITED\\\>
Dim ind As Int32
ind = e.CommandArgument
Dim row As GridViewRow
row = GridView1.Rows(ind)
Dim ddll As DropDownList = New DropDownList
ddll = CType(row.Cells(5).FindControl("ddl2"), DropDownList)
ind = ddll.SelectedValue
End Sub
-
Sep 5th, 2006, 11:57 AM
#14
Thread Starter
Hyperactive Member
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..
-
Sep 6th, 2006, 04:20 AM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|