Hi,
I have a datagrid, and in different rows I need to
programmatically bind different type of controls and load
data into these controls. For example,in the first row I
need to bind data into a textbox, and in the second row I
need to bind data into a dropdownlist...It all depends on
the data I select from the database.
I cannot use TemplateColumn because it has to be the same
type of control for one column.
Thanks a lot,
Julia 18 2409
Julia,
Try something like this:
<asp:TemplateColumn HeaderText="Hotel Type">
<ItemTemplate>
<asp:PlaceHolder ID="plc" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
I'm not sure if you are using c# or vb.net, and what you are binding too,
but assuming you are in vb.net and binding to a dataset/table, your
ItemDatabound event should look something like:
Private Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles grid.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim plc As PlaceHolder = CType(e.Item.FindControl("plc"), PlaceHolder)
If Not plc Is Nothing Then
Dim dr As DataRowView = CType(e.Item.DataItem, DataRowView)
Select Case CInt(dr("type"))
Case 1
Dim txt As New TextBox
txt.Text = CStr(dr("value"))
plc.Controls.Add(txt)
Case 2
Dim ddl As New DropDownList
plc.Controls.Add(ddl)
End Select
End If
End If
End Sub
As you can see, we try to find the placeholder contorl, if it exists, we get
a reference to the current row we are using, we can use the values in the
row (here, I used a mythical "Type" column) to figure out what type of
control goes into the placeholder.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message
news:a8****************************@phx.gbl... Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a textbox, and in the second row I need to bind data into a dropdownlist...It all depends on the data I select from the database.
I cannot use TemplateColumn because it has to be the same type of control for one column.
Thanks a lot,
Julia
Karl,
Thank you for your quick response and appreciate your help!
I will try it and let you know if it works.
Julia -----Original Message----- Julia, Try something like this:
<asp:TemplateColumn HeaderText="Hotel Type"> <ItemTemplate> <asp:PlaceHolder ID="plc" Runat="server" /> </ItemTemplate> </asp:TemplateColumn>
I'm not sure if you are using c# or vb.net, and what you
are binding too,but assuming you are in vb.net and binding to a
dataset/table, yourItemDatabound event should look something like:
Private Sub Grid_ItemDataBound(ByVal sender As Object,
ByVal e AsDataGridItemEventArgs) Handles grid.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType =ListItemType.AlternatingItem Then Dim plc As PlaceHolder = CType(e.Item.FindControl
("plc"), PlaceHolder) If Not plc Is Nothing Then Dim dr As DataRowView = CType
(e.Item.DataItem, DataRowView) Select Case CInt(dr("type")) Case 1 Dim txt As New TextBox txt.Text = CStr(dr("value")) plc.Controls.Add(txt) Case 2 Dim ddl As New DropDownList plc.Controls.Add(ddl) End Select End If End If End Sub
As you can see, we try to find the placeholder contorl,
if it exists, we geta reference to the current row we are using, we can use
the values in therow (here, I used a mythical "Type" column) to figure out
what type ofcontrol goes into the placeholder.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:a8****************************@phx.gbl... Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and
load data into these controls. For example,in the first row I need to bind data into a textbox, and in the second row
I need to bind data into a dropdownlist...It all depends
on the data I select from the database.
I cannot use TemplateColumn because it has to be the
same type of control for one column.
Thanks a lot,
Julia
.
Karl,
The code works. And now I need to retrieve the data in
the dropdownlist which embeded in the placeholder
control. The following is my code does this, however it
returns nothing.
plcAI = CType(grid.Items(i).Cells(1).FindControl
("plcAI"), PlaceHolder)
Dim ddl As DropDownList = CType(plcAI.FindControl
("ddlAI"), DropDownList)
thanks again -----Original Message----- Julia, Try something like this:
<asp:TemplateColumn HeaderText="Hotel Type"> <ItemTemplate> <asp:PlaceHolder ID="plc" Runat="server" /> </ItemTemplate> </asp:TemplateColumn>
I'm not sure if you are using c# or vb.net, and what you
are binding too,but assuming you are in vb.net and binding to a
dataset/table, yourItemDatabound event should look something like:
Private Sub Grid_ItemDataBound(ByVal sender As
Object, ByVal e AsDataGridItemEventArgs) Handles grid.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType =ListItemType.AlternatingItem Then Dim plc As PlaceHolder = CType(e.Item.FindControl
("plc"), PlaceHolder) If Not plc Is Nothing Then Dim dr As DataRowView = CType
(e.Item.DataItem, DataRowView) Select Case CInt(dr("type")) Case 1 Dim txt As New TextBox txt.Text = CStr(dr("value")) plc.Controls.Add(txt) Case 2 Dim ddl As New DropDownList plc.Controls.Add(ddl) End Select End If End If End Sub
As you can see, we try to find the placeholder contorl,
if it exists, we geta reference to the current row we are using, we can use
the values in therow (here, I used a mythical "Type" column) to figure
out what type ofcontrol goes into the placeholder.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:a8****************************@phx.gbl... Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and
load data into these controls. For example,in the first row
I need to bind data into a textbox, and in the second
row I need to bind data into a dropdownlist...It all depends
on the data I select from the database.
I cannot use TemplateColumn because it has to be the
same type of control for one column.
Thanks a lot,
Julia
.
What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message
news:ba****************************@phx.gbl... Karl, The code works. And now I need to retrieve the data in the dropdownlist which embeded in the placeholder control. The following is my code does this, however it returns nothing.
plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList)
thanks again
-----Original Message----- Julia, Try something like this:
<asp:TemplateColumn HeaderText="Hotel Type"> <ItemTemplate> <asp:PlaceHolder ID="plc" Runat="server" /> </ItemTemplate> </asp:TemplateColumn>
I'm not sure if you are using c# or vb.net, and what you are binding too,but assuming you are in vb.net and binding to a dataset/table, yourItemDatabound event should look something like:
Private Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e AsDataGridItemEventArgs) Handles grid.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =ListItemType.AlternatingItem Then Dim plc As PlaceHolder = CType(e.Item.FindControl ("plc"), PlaceHolder) If Not plc Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("type")) Case 1 Dim txt As New TextBox txt.Text = CStr(dr("value")) plc.Controls.Add(txt) Case 2 Dim ddl As New DropDownList plc.Controls.Add(ddl) End Select End If End If End Sub
As you can see, we try to find the placeholder contorl, if it exists, we geta reference to the current row we are using, we can use the values in therow (here, I used a mythical "Type" column) to figure out what type ofcontrol goes into the placeholder.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:a8****************************@phx.gbl... Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a textbox, and in the second row I need to bind data into a dropdownlist...It all depends on the data I select from the database.
I cannot use TemplateColumn because it has to be the same type of control for one column.
Thanks a lot,
Julia
.
plc is not null,but the ddl returns me Nothing!!
thanks -----Original Message----- What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... Karl, The code works. And now I need to retrieve the data in the dropdownlist which embeded in the placeholder control. The following is my code does this, however it returns nothing.
plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList)
thanks again
>-----Original Message----- >Julia, >Try something like this: > ><asp:TemplateColumn HeaderText="Hotel Type"> > <ItemTemplate> > <asp:PlaceHolder ID="plc" Runat="server" /> > </ItemTemplate> ></asp:TemplateColumn> > >I'm not sure if you are using c# or vb.net, and what
you are binding too, >but assuming you are in vb.net and binding to a dataset/table, your >ItemDatabound event should look something like: > > Private Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e As >DataGridItemEventArgs) Handles grid.ItemDataBound > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = >ListItemType.AlternatingItem Then > Dim plc As PlaceHolder = CType
(e.Item.FindControl ("plc"), PlaceHolder) > If Not plc Is Nothing Then > Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) > Select Case CInt(dr("type")) > Case 1 > Dim txt As New TextBox > txt.Text = CStr(dr("value")) > plc.Controls.Add(txt) > Case 2 > Dim ddl As New DropDownList > plc.Controls.Add(ddl) > End Select > End If > End If > End Sub > >As you can see, we try to find the placeholder
contorl, if it exists, we get >a reference to the current row we are using, we can
use the values in the >row (here, I used a mythical "Type" column) to figure out what type of >control goes into the placeholder. > >Karl > >"Julia Hu" <h6**@yahoo.ca> wrote in message >news:a8****************************@phx.gbl... >> Hi, >> I have a datagrid, and in different rows I need to >> programmatically bind different type of controls and load >> data into these controls. For example,in the first
row I >> need to bind data into a textbox, and in the second row I >> need to bind data into a dropdownlist...It all
depends on >> the data I select from the database. >> >> I cannot use TemplateColumn because it has to be the same >> type of control for one column. >> >> Thanks a lot, >> >> Julia > > >. >
.
On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... Karl, The code works. And now I need to retrieve the data in the dropdownlist which embeded in the placeholder control. The following is my code does this, however it returns nothing.
plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList)
thanks again
-----Original Message----- Julia, Try something like this:
<asp:TemplateColumn HeaderText="Hotel Type"> <ItemTemplate> <asp:PlaceHolder ID="plc" Runat="server" /> </ItemTemplate> </asp:TemplateColumn>
I'm not sure if you are using c# or vb.net, and what you are binding too,but assuming you are in vb.net and binding to a dataset/table, yourItemDatabound event should look something like:
Private Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e AsDataGridItemEventArgs) Handles grid.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =ListItemType.AlternatingItem Then Dim plc As PlaceHolder = CType(e.Item.FindControl ("plc"), PlaceHolder) If Not plc Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("type")) Case 1 Dim txt As New TextBox txt.Text = CStr(dr("value")) plc.Controls.Add(txt) Case 2 Dim ddl As New DropDownList plc.Controls.Add(ddl) End Select End If End If End Sub
As you can see, we try to find the placeholder contorl, if it exists, we geta reference to the current row we are using, we can use the values in therow (here, I used a mythical "Type" column) to figure out what type ofcontrol goes into the placeholder.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:a8****************************@phx.gbl... > Hi, > I have a datagrid, and in different rows I need to > programmatically bind different type of controls and load> data into these controls. For example,in the first row I> need to bind data into a textbox, and in the second row I> need to bind data into a dropdownlist...It all depends on> the data I select from the database. > > I cannot use TemplateColumn because it has to be the same> type of control for one column. > > Thanks a lot, > > Julia
.
As you told me, I loaded controls in ItemDataBound event,
and how can I re-add them?
code like this:
Private Sub grdAI_ItemDataBound(ByVal sender As Object,
ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdAI.ItemDataBound
Dim i As Integer
Dim plcAI As PlaceHolder = CType
(e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then
Dim dr As DataRowView = CType
(e.Item.DataItem, DataRowView)
Select Case CInt(dr("FieldType"))
Case 6 'ListView type
Dim ddlAI As New DropDownList
ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big")
ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else
Dim txt As New TextBox
txt.Text = ""
plcAI.Controls.Add(txt)
End Select
End If
End Sub -----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... > Karl, > The code works. And now I need to retrieve the data
in > the dropdownlist which embeded in the placeholder > control. The following is my code does this, however
it > returns nothing. > > plcAI = CType(grid.Items(i).Cells(1).FindControl > ("plcAI"), PlaceHolder) > Dim ddl As DropDownList = CType(plcAI.FindControl > ("ddlAI"), DropDownList) > > thanks again > > >-----Original Message----- > >Julia, > >Try something like this: > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > <ItemTemplate> > > <asp:PlaceHolder ID="plc" Runat="server" /> > > </ItemTemplate> > ></asp:TemplateColumn> > > > >I'm not sure if you are using c# or vb.net, and
what you > are binding too, > >but assuming you are in vb.net and binding to a > dataset/table, your > >ItemDatabound event should look something like: > > > > Private Sub Grid_ItemDataBound(ByVal sender As > Object, ByVal e As > >DataGridItemEventArgs) Handles grid.ItemDataBound > > If e.Item.ItemType = ListItemType.Item OrElse > e.Item.ItemType = > >ListItemType.AlternatingItem Then > > Dim plc As PlaceHolder = CType
(e.Item.FindControl > ("plc"), PlaceHolder) > > If Not plc Is Nothing Then > > Dim dr As DataRowView = CType > (e.Item.DataItem, DataRowView) > > Select Case CInt(dr("type")) > > Case 1 > > Dim txt As New TextBox > > txt.Text = CStr(dr("value")) > > plc.Controls.Add(txt) > > Case 2 > > Dim ddl As New DropDownList > > plc.Controls.Add(ddl) > > End Select > > End If > > End If > > End Sub > > > >As you can see, we try to find the placeholder
contorl, > if it exists, we get > >a reference to the current row we are using, we can
use > the values in the > >row (here, I used a mythical "Type" column) to
figure > out what type of > >control goes into the placeholder. > > > >Karl > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > >news:a8****************************@phx.gbl... > >> Hi, > >> I have a datagrid, and in different rows I need to > >> programmatically bind different type of controls
and > load > >> data into these controls. For example,in the
first row > I > >> need to bind data into a textbox, and in the
second > row I > >> need to bind data into a dropdownlist...It all
depends > on > >> the data I select from the database. > >> > >> I cannot use TemplateColumn because it has to be
the > same > >> type of control for one column. > >> > >> Thanks a lot, > >> > >> Julia > > > > > >. > >
.
You have two solutions, neither is particularly nice.
One of those solution is to rebuild the controls. The other one is to
access their value directly from Request.Form() Your problem with the
request.Form is figuring out what the name of the damn thing will be (it
won't be random - far from it actually). It'll be something like grid.id +
":" + row.id +... well not nearly that, but something along the lines of
parentId appended to childId.
The other solution is, as I mentioned, to rebuild the controls. This
solution has its own ugliness...if the above method will work for you, I
suggest you try it out. Otherwise, you'll need to store values in the
ViewState that says which controls were loaded, then on page_load, read the
viewstate, reload everything, and you'll be able to access them. You can
clean things up a lot by refactoring the creationg code.
For example, instead of adding the ddl when case 6, simply call a method,
which your page_load can also call.
case 6 'listvie type
AddListView("ddlAI")
Anyways, try the first solution (or maybe something else)...if ti doesn't
work and you need more help with the 2nd one, let me know.
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message
news:47****************************@phx.gbl... As you told me, I loaded controls in ItemDataBound event, and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
-----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... > Karl, > The code works. And now I need to retrieve the data in > the dropdownlist which embeded in the placeholder > control. The following is my code does this, however it > returns nothing. > > plcAI = CType(grid.Items(i).Cells(1).FindControl > ("plcAI"), PlaceHolder) > Dim ddl As DropDownList = CType(plcAI.FindControl > ("ddlAI"), DropDownList) > > thanks again > > >-----Original Message----- > >Julia, > >Try something like this: > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > <ItemTemplate> > > <asp:PlaceHolder ID="plc" Runat="server" /> > > </ItemTemplate> > ></asp:TemplateColumn> > > > >I'm not sure if you are using c# or vb.net, and what you > are binding too, > >but assuming you are in vb.net and binding to a > dataset/table, your > >ItemDatabound event should look something like: > > > > Private Sub Grid_ItemDataBound(ByVal sender As > Object, ByVal e As > >DataGridItemEventArgs) Handles grid.ItemDataBound > > If e.Item.ItemType = ListItemType.Item OrElse > e.Item.ItemType = > >ListItemType.AlternatingItem Then > > Dim plc As PlaceHolder = CType (e.Item.FindControl > ("plc"), PlaceHolder) > > If Not plc Is Nothing Then > > Dim dr As DataRowView = CType > (e.Item.DataItem, DataRowView) > > Select Case CInt(dr("type")) > > Case 1 > > Dim txt As New TextBox > > txt.Text = CStr(dr("value")) > > plc.Controls.Add(txt) > > Case 2 > > Dim ddl As New DropDownList > > plc.Controls.Add(ddl) > > End Select > > End If > > End If > > End Sub > > > >As you can see, we try to find the placeholder contorl, > if it exists, we get > >a reference to the current row we are using, we can use > the values in the > >row (here, I used a mythical "Type" column) to figure > out what type of > >control goes into the placeholder. > > > >Karl > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > >news:a8****************************@phx.gbl... > >> Hi, > >> I have a datagrid, and in different rows I need to > >> programmatically bind different type of controls and > load > >> data into these controls. For example,in the first row > I > >> need to bind data into a textbox, and in the second > row I > >> need to bind data into a dropdownlist...It all depends > on > >> the data I select from the database. > >> > >> I cannot use TemplateColumn because it has to be the > same > >> type of control for one column. > >> > >> Thanks a lot, > >> > >> Julia > > > > > >. > >
.
If I reload controls again in postback, the selected item
of the dropdownlist will be lost. How do I keep it? -----Original Message----- As you told me, I loaded controls in ItemDataBound
event,and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As
Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs ) Handles grdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
-----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in messagenews:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... > Karl, > The code works. And now I need to retrieve the datain > the dropdownlist which embeded in the placeholder > control. The following is my code does this,
howeverit > returns nothing. > > plcAI = CType(grid.Items(i).Cells(1).FindControl > ("plcAI"), PlaceHolder) > Dim ddl As DropDownList = CType(plcAI.FindControl > ("ddlAI"), DropDownList) > > thanks again > > >-----Original Message----- > >Julia, > >Try something like this: > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > <ItemTemplate> > > <asp:PlaceHolder ID="plc" Runat="server" /> > > </ItemTemplate> > ></asp:TemplateColumn> > > > >I'm not sure if you are using c# or vb.net, andwhat you > are binding too, > >but assuming you are in vb.net and binding to a > dataset/table, your > >ItemDatabound event should look something like: > > > > Private Sub Grid_ItemDataBound(ByVal sender As > Object, ByVal e As > >DataGridItemEventArgs) Handles grid.ItemDataBound > > If e.Item.ItemType = ListItemType.Item OrElse > e.Item.ItemType = > >ListItemType.AlternatingItem Then > > Dim plc As PlaceHolder = CType(e.Item.FindControl > ("plc"), PlaceHolder) > > If Not plc Is Nothing Then > > Dim dr As DataRowView = CType > (e.Item.DataItem, DataRowView) > > Select Case CInt(dr("type")) > > Case 1 > > Dim txt As New TextBox > > txt.Text = CStr(dr("value")) > > plc.Controls.Add(txt) > > Case 2 > > Dim ddl As New DropDownList > > plc.Controls.Add(ddl) > > End Select > > End If > > End If > > End Sub > > > >As you can see, we try to find the placeholdercontorl, > if it exists, we get > >a reference to the current row we are using, we
canuse > the values in the > >row (here, I used a mythical "Type" column) tofigure > out what type of > >control goes into the placeholder. > > > >Karl > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > >news:a8****************************@phx.gbl... > >> Hi, > >> I have a datagrid, and in different rows I need
to > >> programmatically bind different type of controls
and > load > >> data into these controls. For example,in thefirst row > I > >> need to bind data into a textbox, and in thesecond > row I > >> need to bind data into a dropdownlist...It alldepends > on > >> the data I select from the database. > >> > >> I cannot use TemplateColumn because it has to bethe > same > >> type of control for one column. > >> > >> Thanks a lot, > >> > >> Julia > > > > > >. > >
. .
If it gets re-added in the page_load, it'll happen before the Begin
ProcessPostData Second Try which will preserve the value...If you do it in
the button click, you'll lose it.
Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote in message
news:ba****************************@phx.gbl... If I reload controls again in postback, the selected item of the dropdownlist will be lost. How do I keep it?
-----Original Message----- As you told me, I loaded controls in ItemDataBound event,and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs ) Handles grdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
-----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... > Karl, > The code works. And now I need to retrieve the data in > the dropdownlist which embeded in the placeholder > control. The following is my code does this, howeverit > returns nothing. > > plcAI = CType(grid.Items(i).Cells(1).FindControl > ("plcAI"), PlaceHolder) > Dim ddl As DropDownList = CType(plcAI.FindControl > ("ddlAI"), DropDownList) > > thanks again > > >-----Original Message----- > >Julia, > >Try something like this: > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > <ItemTemplate> > > <asp:PlaceHolder ID="plc" Runat="server" /> > > </ItemTemplate> > ></asp:TemplateColumn> > > > >I'm not sure if you are using c# or vb.net, and what you > are binding too, > >but assuming you are in vb.net and binding to a > dataset/table, your > >ItemDatabound event should look something like: > > > > Private Sub Grid_ItemDataBound(ByVal sender As > Object, ByVal e As > >DataGridItemEventArgs) Handles grid.ItemDataBound > > If e.Item.ItemType = ListItemType.Item OrElse > e.Item.ItemType = > >ListItemType.AlternatingItem Then > > Dim plc As PlaceHolder = CType (e.Item.FindControl > ("plc"), PlaceHolder) > > If Not plc Is Nothing Then > > Dim dr As DataRowView = CType > (e.Item.DataItem, DataRowView) > > Select Case CInt(dr("type")) > > Case 1 > > Dim txt As New TextBox > > txt.Text = CStr(dr("value")) > > plc.Controls.Add(txt) > > Case 2 > > Dim ddl As New DropDownList > > plc.Controls.Add(ddl) > > End Select > > End If > > End If > > End Sub > > > >As you can see, we try to find the placeholder contorl, > if it exists, we get > >a reference to the current row we are using, we canuse > the values in the > >row (here, I used a mythical "Type" column) to figure > out what type of > >control goes into the placeholder. > > > >Karl > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > >news:a8****************************@phx.gbl... > >> Hi, > >> I have a datagrid, and in different rows I need to > >> programmatically bind different type of controls and > load > >> data into these controls. For example,in the first row > I > >> need to bind data into a textbox, and in the second > row I > >> need to bind data into a dropdownlist...It all depends > on > >> the data I select from the database. > >> > >> I cannot use TemplateColumn because it has to be the > same > >> type of control for one column. > >> > >> Thanks a lot, > >> > >> Julia > > > > > >. > >
. .
I tried both ClientID and UniqueID and the UniqueID
works!! I got the SelectedValue, and how can I get the
SelectedText?? -----Original Message----- If I reload controls again in postback, the selected
itemof the dropdownlist will be lost. How do I keep it?
-----Original Message----- As you told me, I loaded controls in ItemDataBound event,and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArg s)
HandlesgrdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
-----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... What's null, plcAI or ddl?
Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:ba****************************@phx.gbl... > Karl, > The code works. And now I need to retrieve the
datain > the dropdownlist which embeded in the placeholder > control. The following is my code does this,howeverit > returns nothing. > > plcAI = CType(grid.Items(i).Cells(1).FindControl > ("plcAI"), PlaceHolder) > Dim ddl As DropDownList = CType(plcAI.FindControl > ("ddlAI"), DropDownList) > > thanks again > > >-----Original Message----- > >Julia, > >Try something like this: > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > <ItemTemplate> > > <asp:PlaceHolder ID="plc" Runat="server" /> > > </ItemTemplate> > ></asp:TemplateColumn> > > > >I'm not sure if you are using c# or vb.net, and what you > are binding too, > >but assuming you are in vb.net and binding to a > dataset/table, your > >ItemDatabound event should look something like: > > > > Private Sub Grid_ItemDataBound(ByVal sender As > Object, ByVal e As > >DataGridItemEventArgs) Handles grid.ItemDataBound > > If e.Item.ItemType = ListItemType.Item
OrElse > e.Item.ItemType = > >ListItemType.AlternatingItem Then > > Dim plc As PlaceHolder = CType (e.Item.FindControl > ("plc"), PlaceHolder) > > If Not plc Is Nothing Then > > Dim dr As DataRowView = CType > (e.Item.DataItem, DataRowView) > > Select Case CInt(dr("type")) > > Case 1 > > Dim txt As New TextBox > > txt.Text = CStr(dr("value")) > > plc.Controls.Add(txt) > > Case 2 > > Dim ddl As New DropDownList > > plc.Controls.Add(ddl) > > End Select > > End If > > End If > > End Sub > > > >As you can see, we try to find the placeholder contorl, > if it exists, we get > >a reference to the current row we are using, we
canuse > the values in the > >row (here, I used a mythical "Type" column) to figure > out what type of > >control goes into the placeholder. > > > >Karl > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > >news:a8****************************@phx.gbl... > >> Hi, > >> I have a datagrid, and in different rows I need to > >> programmatically bind different type of
controlsand > load > >> data into these controls. For example,in the first row > I > >> need to bind data into a textbox, and in the second > row I > >> need to bind data into a dropdownlist...It all depends > on > >> the data I select from the database. > >> > >> I cannot use TemplateColumn because it has to
bethe > same > >> type of control for one column. > >> > >> Thanks a lot, > >> > >> Julia > > > > > >. > >
. . .
Really appreciate your assistance!
I tried both ClientID and UniqueID and the UniqueID
works!! I got the SelectedValue, and how can I get the
SelectedText?? -----Original Message----- You have two solutions, neither is particularly nice.
One of those solution is to rebuild the controls. The
other one is toaccess their value directly from Request.Form() Your
problem with therequest.Form is figuring out what the name of the damn
thing will be (itwon't be random - far from it actually). It'll be
something like grid.id +":" + row.id +... well not nearly that, but something
along the lines ofparentId appended to childId.
The other solution is, as I mentioned, to rebuild the
controls. Thissolution has its own ugliness...if the above method will
work for you, Isuggest you try it out. Otherwise, you'll need to store
values in theViewState that says which controls were loaded, then on
page_load, read theviewstate, reload everything, and you'll be able to
access them. You canclean things up a lot by refactoring the creationg code.
For example, instead of adding the ddl when case 6,
simply call a method,which your page_load can also call. case 6 'listvie type AddListView("ddlAI")
Anyways, try the first solution (or maybe something
else)...if ti doesn'twork and you need more help with the 2nd one, let me
know. Karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:47****************************@phx.gbl... As you told me, I loaded controls in ItemDataBound
event, and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Handles grdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
>-----Original Message----- >On postback you'll need to re-add the controls > >Karl > >"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... >> What's null, plcAI or ddl? >> >> Karl >> >> "Julia Hu" <h6**@yahoo.ca> wrote in message >> news:ba****************************@phx.gbl... >> > Karl, >> > The code works. And now I need to retrieve the
data in >> > the dropdownlist which embeded in the placeholder >> > control. The following is my code does this,
however it >> > returns nothing. >> > >> > plcAI = CType(grid.Items(i).Cells(1).FindControl >> > ("plcAI"), PlaceHolder) >> > Dim ddl As DropDownList = CType(plcAI.FindControl >> > ("ddlAI"), DropDownList) >> > >> > thanks again >> > >> > >-----Original Message----- >> > >Julia, >> > >Try something like this: >> > > >> > ><asp:TemplateColumn HeaderText="Hotel Type"> >> > > <ItemTemplate> >> > > <asp:PlaceHolder ID="plc" Runat="server" /> >> > > </ItemTemplate> >> > ></asp:TemplateColumn> >> > > >> > >I'm not sure if you are using c# or vb.net, and what you >> > are binding too, >> > >but assuming you are in vb.net and binding to a >> > dataset/table, your >> > >ItemDatabound event should look something like: >> > > >> > > Private Sub Grid_ItemDataBound(ByVal sender As >> > Object, ByVal e As >> > >DataGridItemEventArgs) Handles grid.ItemDataBound >> > > If e.Item.ItemType = ListItemType.Item
OrElse >> > e.Item.ItemType = >> > >ListItemType.AlternatingItem Then >> > > Dim plc As PlaceHolder = CType (e.Item.FindControl >> > ("plc"), PlaceHolder) >> > > If Not plc Is Nothing Then >> > > Dim dr As DataRowView = CType >> > (e.Item.DataItem, DataRowView) >> > > Select Case CInt(dr("type")) >> > > Case 1 >> > > Dim txt As New TextBox >> > > txt.Text = CStr(dr("value")) >> > > plc.Controls.Add(txt) >> > > Case 2 >> > > Dim ddl As New DropDownList >> > > plc.Controls.Add(ddl) >> > > End Select >> > > End If >> > > End If >> > > End Sub >> > > >> > >As you can see, we try to find the placeholder contorl, >> > if it exists, we get >> > >a reference to the current row we are using, we
can use >> > the values in the >> > >row (here, I used a mythical "Type" column) to figure >> > out what type of >> > >control goes into the placeholder. >> > > >> > >Karl >> > > >> > >"Julia Hu" <h6**@yahoo.ca> wrote in message >> > >news:a8****************************@phx.gbl... >> > >> Hi, >> > >> I have a datagrid, and in different rows I
need to >> > >> programmatically bind different type of
controls and >> > load >> > >> data into these controls. For example,in the first row >> > I >> > >> need to bind data into a textbox, and in the second >> > row I >> > >> need to bind data into a dropdownlist...It all depends >> > on >> > >> the data I select from the database. >> > >> >> > >> I cannot use TemplateColumn because it has to
be the >> > same >> > >> type of control for one column. >> > >> >> > >> Thanks a lot, >> > >> >> > >> Julia >> > > >> > > >> > >. >> > > >> >> > > >. >
.
You can't directly....this gets uglier, doesn't it? If you rebuild you can,
if you don't you just have access to the value...although from the value you
can obvious get the text either by hitting your database or cache..
Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote in message
news:bc****************************@phx.gbl... I tried both ClientID and UniqueID and the UniqueID works!! I got the SelectedValue, and how can I get the SelectedText??
-----Original Message----- If I reload controls again in postback, the selected itemof the dropdownlist will be lost. How do I keep it?
-----Original Message----- As you told me, I loaded controls in ItemDataBound event,and how can I re-add them? code like this: Private Sub grdAI_ItemDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArg s) HandlesgrdAI.ItemDataBound Dim i As Integer Dim plcAI As PlaceHolder = CType (e.Item.FindControl("plcAI"), PlaceHolder)
If Not plcAI Is Nothing Then Dim dr As DataRowView = CType (e.Item.DataItem, DataRowView) Select Case CInt(dr("FieldType")) Case 6 'ListView type Dim ddlAI As New DropDownList ddlAI.ID = "ddlAI"
ddlAI.Items.Add("Big") ddlAI.Items.Add("Small")
plcAI.Controls.Add(ddlAI)
Case Else Dim txt As New TextBox txt.Text = "" plcAI.Controls.Add(txt) End Select End If
End Sub
-----Original Message----- On postback you'll need to re-add the controls
Karl
"Karl" <none> wrote in message news:eB**************@TK2MSFTNGP12.phx.gbl... > What's null, plcAI or ddl? > > Karl > > "Julia Hu" <h6**@yahoo.ca> wrote in message > news:ba****************************@phx.gbl... > > Karl, > > The code works. And now I need to retrieve the datain > > the dropdownlist which embeded in the placeholder > > control. The following is my code does this, howeverit > > returns nothing. > > > > plcAI = CType(grid.Items(i).Cells(1).FindControl > > ("plcAI"), PlaceHolder) > > Dim ddl As DropDownList = CType(plcAI.FindControl > > ("ddlAI"), DropDownList) > > > > thanks again > > > > >-----Original Message----- > > >Julia, > > >Try something like this: > > > > > ><asp:TemplateColumn HeaderText="Hotel Type"> > > > <ItemTemplate> > > > <asp:PlaceHolder ID="plc" Runat="server" /> > > > </ItemTemplate> > > ></asp:TemplateColumn> > > > > > >I'm not sure if you are using c# or vb.net, and what you > > are binding too, > > >but assuming you are in vb.net and binding to a > > dataset/table, your > > >ItemDatabound event should look something like: > > > > > > Private Sub Grid_ItemDataBound(ByVal sender As > > Object, ByVal e As > > >DataGridItemEventArgs) Handles grid.ItemDataBound > > > If e.Item.ItemType = ListItemType.Item OrElse> > e.Item.ItemType = > > >ListItemType.AlternatingItem Then > > > Dim plc As PlaceHolder = CType (e.Item.FindControl > > ("plc"), PlaceHolder) > > > If Not plc Is Nothing Then > > > Dim dr As DataRowView = CType > > (e.Item.DataItem, DataRowView) > > > Select Case CInt(dr("type")) > > > Case 1 > > > Dim txt As New TextBox > > > txt.Text = CStr(dr("value")) > > > plc.Controls.Add(txt) > > > Case 2 > > > Dim ddl As New DropDownList > > > plc.Controls.Add(ddl) > > > End Select > > > End If > > > End If > > > End Sub > > > > > >As you can see, we try to find the placeholder contorl, > > if it exists, we get > > >a reference to the current row we are using, we canuse > > the values in the > > >row (here, I used a mythical "Type" column) to figure > > out what type of > > >control goes into the placeholder. > > > > > >Karl > > > > > >"Julia Hu" <h6**@yahoo.ca> wrote in message > > >news:a8****************************@phx.gbl... > > >> Hi, > > >> I have a datagrid, and in different rows I need to> > >> programmatically bind different type of controlsand > > load > > >> data into these controls. For example,in the first row > > I > > >> need to bind data into a textbox, and in the second > > row I > > >> need to bind data into a dropdownlist...It all depends > > on > > >> the data I select from the database. > > >> > > >> I cannot use TemplateColumn because it has to bethe > > same > > >> type of control for one column. > > >> > > >> Thanks a lot, > > >> > > >> Julia > > > > > > > > >. > > > > >
.
. .
Yes,just one more database call.
I still have 2 questions:
First,the UniqueID will never change if I keep the same
columns structure in the datagrid?
Second,if I use your 2nd solution to reload data,can I
put in Page_PreRender instead of Page_Load? And can I
still use the FindControl method to find "plc" and "ddl"
like this
plcAI = CType(grid.Items(i).Cells(1).FindControl
("plcAI"), PlaceHolder)
Dim ddl As DropDownList = CType(plcAI.FindControl
("ddlAI"), DropDownList) ??
thank you very much -----Original Message----- You can't directly....this gets uglier, doesn't it? If
you rebuild you can,if you don't you just have access to the
value...although from the value youcan obvious get the text either by hitting your database
or cache.. Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote
in messagenews:bc****************************@phx.gbl... I tried both ClientID and UniqueID and the UniqueID works!! I got the SelectedValue, and how can I get the SelectedText??
>-----Original Message----- >If I reload controls again in postback, the selected item >of the dropdownlist will be lost. How do I keep it? > > >>-----Original Message----- >>As you told me, I loaded controls in ItemDataBound >event, >>and how can I re-add them? >>code like this: >> Private Sub grdAI_ItemDataBound(ByVal sender As >Object, >>ByVal e As >>System.Web.UI.WebControls.DataGridItemEventArg s) Handles >>grdAI.ItemDataBound >> Dim i As Integer >> Dim plcAI As PlaceHolder = CType >>(e.Item.FindControl("plcAI"), PlaceHolder) >> >> If Not plcAI Is Nothing Then >> Dim dr As DataRowView = CType >>(e.Item.DataItem, DataRowView) >> Select Case CInt(dr("FieldType")) >> Case 6 'ListView type >> Dim ddlAI As New DropDownList >> ddlAI.ID = "ddlAI" >> >> ddlAI.Items.Add("Big") >> ddlAI.Items.Add("Small") >> >> plcAI.Controls.Add(ddlAI) >> >> >> Case Else >> Dim txt As New TextBox >> txt.Text = "" >> plcAI.Controls.Add(txt) >> End Select >> End If >> >> End Sub >> >>>-----Original Message----- >>>On postback you'll need to re-add the controls >>> >>>Karl >>> >>>"Karl" <none> wrote in message >>news:eB**************@TK2MSFTNGP12.phx.gbl... >>>> What's null, plcAI or ddl? >>>> >>>> Karl >>>> >>>> "Julia Hu" <h6**@yahoo.ca> wrote in message >>>> news:ba****************************@phx.gbl... >>>> > Karl, >>>> > The code works. And now I need to retrieve the data >>in >>>> > the dropdownlist which embeded in the
placeholder >>>> > control. The following is my code does this, >however >>it >>>> > returns nothing. >>>> > >>>> > plcAI = CType(grid.Items(i).Cells
(1).FindControl >>>> > ("plcAI"), PlaceHolder) >>>> > Dim ddl As DropDownList = CType
(plcAI.FindControl >>>> > ("ddlAI"), DropDownList) >>>> > >>>> > thanks again >>>> > >>>> > >-----Original Message----- >>>> > >Julia, >>>> > >Try something like this: >>>> > > >>>> > ><asp:TemplateColumn HeaderText="Hotel Type"> >>>> > > <ItemTemplate> >>>> > > <asp:PlaceHolder ID="plc"
Runat="server" /> >>>> > > </ItemTemplate> >>>> > ></asp:TemplateColumn> >>>> > > >>>> > >I'm not sure if you are using c# or vb.net, and >>what you >>>> > are binding too, >>>> > >but assuming you are in vb.net and binding to a >>>> > dataset/table, your >>>> > >ItemDatabound event should look something like: >>>> > > >>>> > > Private Sub Grid_ItemDataBound(ByVal sender
As >>>> > Object, ByVal e As >>>> > >DataGridItemEventArgs) Handles
grid.ItemDataBound >>>> > > If e.Item.ItemType = ListItemType.Item OrElse >>>> > e.Item.ItemType = >>>> > >ListItemType.AlternatingItem Then >>>> > > Dim plc As PlaceHolder = CType >>(e.Item.FindControl >>>> > ("plc"), PlaceHolder) >>>> > > If Not plc Is Nothing Then >>>> > > Dim dr As DataRowView = CType >>>> > (e.Item.DataItem, DataRowView) >>>> > > Select Case CInt(dr("type")) >>>> > > Case 1 >>>> > > Dim txt As New TextBox >>>> > > txt.Text = CStr(dr("value")) >>>> > > plc.Controls.Add(txt) >>>> > > Case 2 >>>> > > Dim ddl As New DropDownList >>>> > > plc.Controls.Add(ddl) >>>> > > End Select >>>> > > End If >>>> > > End If >>>> > > End Sub >>>> > > >>>> > >As you can see, we try to find the placeholder >>contorl, >>>> > if it exists, we get >>>> > >a reference to the current row we are using, we >can >>use >>>> > the values in the >>>> > >row (here, I used a mythical "Type" column) to >>figure >>>> > out what type of >>>> > >control goes into the placeholder. >>>> > > >>>> > >Karl >>>> > > >>>> > >"Julia Hu" <h6**@yahoo.ca> wrote in message >>>> > >news:a8****************************@phx.gbl... >>>> > >> Hi, >>>> > >> I have a datagrid, and in different rows I
need >to >>>> > >> programmatically bind different type of controls >>and >>>> > load >>>> > >> data into these controls. For example,in the >>first row >>>> > I >>>> > >> need to bind data into a textbox, and in the >>second >>>> > row I >>>> > >> need to bind data into a dropdownlist...It
all >>depends >>>> > on >>>> > >> the data I select from the database. >>>> > >> >>>> > >> I cannot use TemplateColumn because it has to be >>the >>>> > same >>>> > >> type of control for one column. >>>> > >> >>>> > >> Thanks a lot, >>>> > >> >>>> > >> Julia >>>> > > >>>> > > >>>> > >. >>>> > > >>>> >>>> >>> >>> >>>. >>> >>. >> >. >
.
it isn't an extra call if you cache the data...which is obviously something
you should consider at this point.
I believe that the id's won't change if the structure is the same, and you
specify the same ID for the ones you have control of.
Page_PreRender I believe so, but remember that your placeholder won't exist
until AFTER you bind the data to the grid. So before you do anything in
page_load you need your grid to be bound to it's source. Unless you
absolutely need the UI re-constructed after you post, I'd really recommend
you try and get away with the Request.Form. You might also have luck
searching for similar solution *dynamically added controls* or something.
Finally, if you post again to this newsgroup in a new thread, I won't reply,
so you might get the input of someone else and find a better answer (I say I
won't reply 'cuz if the other helpers are like me, they rarely reply if they
see that a post has a reply). Of course we can keep this thread going :)
Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote in message
news:b8****************************@phx.gbl... Yes,just one more database call. I still have 2 questions: First,the UniqueID will never change if I keep the same columns structure in the datagrid? Second,if I use your 2nd solution to reload data,can I put in Page_PreRender instead of Page_Load? And can I still use the FindControl method to find "plc" and "ddl" like this plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList) ??
thank you very much
-----Original Message----- You can't directly....this gets uglier, doesn't it? If you rebuild you can,if you don't you just have access to the value...although from the value youcan obvious get the text either by hitting your database or cache.. Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote
in messagenews:bc****************************@phx.gbl... I tried both ClientID and UniqueID and the UniqueID works!! I got the SelectedValue, and how can I get the SelectedText??
>-----Original Message----- >If I reload controls again in postback, the selected item >of the dropdownlist will be lost. How do I keep it? > > >>-----Original Message----- >>As you told me, I loaded controls in ItemDataBound >event, >>and how can I re-add them? >>code like this: >> Private Sub grdAI_ItemDataBound(ByVal sender As >Object, >>ByVal e As >>System.Web.UI.WebControls.DataGridItemEventArg s) Handles >>grdAI.ItemDataBound >> Dim i As Integer >> Dim plcAI As PlaceHolder = CType >>(e.Item.FindControl("plcAI"), PlaceHolder) >> >> If Not plcAI Is Nothing Then >> Dim dr As DataRowView = CType >>(e.Item.DataItem, DataRowView) >> Select Case CInt(dr("FieldType")) >> Case 6 'ListView type >> Dim ddlAI As New DropDownList >> ddlAI.ID = "ddlAI" >> >> ddlAI.Items.Add("Big") >> ddlAI.Items.Add("Small") >> >> plcAI.Controls.Add(ddlAI) >> >> >> Case Else >> Dim txt As New TextBox >> txt.Text = "" >> plcAI.Controls.Add(txt) >> End Select >> End If >> >> End Sub >> >>>-----Original Message----- >>>On postback you'll need to re-add the controls >>> >>>Karl >>> >>>"Karl" <none> wrote in message >>news:eB**************@TK2MSFTNGP12.phx.gbl... >>>> What's null, plcAI or ddl? >>>> >>>> Karl >>>> >>>> "Julia Hu" <h6**@yahoo.ca> wrote in message >>>> news:ba****************************@phx.gbl... >>>> > Karl, >>>> > The code works. And now I need to retrieve the data >>in >>>> > the dropdownlist which embeded in the placeholder >>>> > control. The following is my code does this, >however >>it >>>> > returns nothing. >>>> > >>>> > plcAI = CType(grid.Items(i).Cells (1).FindControl >>>> > ("plcAI"), PlaceHolder) >>>> > Dim ddl As DropDownList = CType (plcAI.FindControl >>>> > ("ddlAI"), DropDownList) >>>> > >>>> > thanks again >>>> > >>>> > >-----Original Message----- >>>> > >Julia, >>>> > >Try something like this: >>>> > > >>>> > ><asp:TemplateColumn HeaderText="Hotel Type"> >>>> > > <ItemTemplate> >>>> > > <asp:PlaceHolder ID="plc" Runat="server" /> >>>> > > </ItemTemplate> >>>> > ></asp:TemplateColumn> >>>> > > >>>> > >I'm not sure if you are using c# or vb.net, and >>what you >>>> > are binding too, >>>> > >but assuming you are in vb.net and binding to a >>>> > dataset/table, your >>>> > >ItemDatabound event should look something like: >>>> > > >>>> > > Private Sub Grid_ItemDataBound(ByVal sender As >>>> > Object, ByVal e As >>>> > >DataGridItemEventArgs) Handles grid.ItemDataBound >>>> > > If e.Item.ItemType = ListItemType.Item OrElse >>>> > e.Item.ItemType = >>>> > >ListItemType.AlternatingItem Then >>>> > > Dim plc As PlaceHolder = CType >>(e.Item.FindControl >>>> > ("plc"), PlaceHolder) >>>> > > If Not plc Is Nothing Then >>>> > > Dim dr As DataRowView = CType >>>> > (e.Item.DataItem, DataRowView) >>>> > > Select Case CInt(dr("type")) >>>> > > Case 1 >>>> > > Dim txt As New TextBox >>>> > > txt.Text = CStr(dr("value")) >>>> > > plc.Controls.Add(txt) >>>> > > Case 2 >>>> > > Dim ddl As New DropDownList >>>> > > plc.Controls.Add(ddl) >>>> > > End Select >>>> > > End If >>>> > > End If >>>> > > End Sub >>>> > > >>>> > >As you can see, we try to find the placeholder >>contorl, >>>> > if it exists, we get >>>> > >a reference to the current row we are using, we >can >>use >>>> > the values in the >>>> > >row (here, I used a mythical "Type" column) to >>figure >>>> > out what type of >>>> > >control goes into the placeholder. >>>> > > >>>> > >Karl >>>> > > >>>> > >"Julia Hu" <h6**@yahoo.ca> wrote in message >>>> > >news:a8****************************@phx.gbl... >>>> > >> Hi, >>>> > >> I have a datagrid, and in different rows I need >to >>>> > >> programmatically bind different type of controls >>and >>>> > load >>>> > >> data into these controls. For example,in the >>first row >>>> > I >>>> > >> need to bind data into a textbox, and in the >>second >>>> > row I >>>> > >> need to bind data into a dropdownlist...It all >>depends >>>> > on >>>> > >> the data I select from the database. >>>> > >> >>>> > >> I cannot use TemplateColumn because it has to be >>the >>>> > same >>>> > >> type of control for one column. >>>> > >> >>>> > >> Thanks a lot, >>>> > >> >>>> > >> Julia >>>> > > >>>> > > >>>> > >. >>>> > > >>>> >>>> >>> >>> >>>. >>> >>. >> >. >
.
Thank you very much for your help!
I probably will have questions about this PlaceHolder
control in the near future, and I'd like to keep this
thread going and hope you can give me some advice.
I guess this is the only way to contact you directly 'cuz
I don't have your email address.
Regards,
Julia -----Original Message----- it isn't an extra call if you cache the data...which is
obviously somethingyou should consider at this point.
I believe that the id's won't change if the structure is
the same, and youspecify the same ID for the ones you have control of.
Page_PreRender I believe so, but remember that your
placeholder won't existuntil AFTER you bind the data to the grid. So before
you do anything inpage_load you need your grid to be bound to it's
source. Unless youabsolutely need the UI re-constructed after you post,
I'd really recommendyou try and get away with the Request.Form. You might
also have lucksearching for similar solution *dynamically added
controls* or something. Finally, if you post again to this newsgroup in a new
thread, I won't reply,so you might get the input of someone else and find a
better answer (I say Iwon't reply 'cuz if the other helpers are like me, they
rarely reply if theysee that a post has a reply). Of course we can keep
this thread going :) Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote
in messagenews:b8****************************@phx.gbl... Yes,just one more database call. I still have 2 questions: First,the UniqueID will never change if I keep the same columns structure in the datagrid? Second,if I use your 2nd solution to reload data,can I put in Page_PreRender instead of Page_Load? And can I still use the FindControl method to find "plc"
and "ddl" like this plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList) ??
thank you very much
>-----Original Message----- >You can't directly....this gets uglier, doesn't it?
If you rebuild you can, >if you don't you just have access to the value...although from the value you >can obvious get the text either by hitting your
database or cache.. > >Karl > >"Julia Hu" <an*******@discussions.microsoft.com> wrote in message >news:bc****************************@phx.gbl... >> I tried both ClientID and UniqueID and the UniqueID >> works!! I got the SelectedValue, and how can I get
the >> SelectedText?? >> >> >-----Original Message----- >> >If I reload controls again in postback, the
selected >> item >> >of the dropdownlist will be lost. How do I keep it? >> > >> > >> >>-----Original Message----- >> >>As you told me, I loaded controls in ItemDataBound >> >event, >> >>and how can I re-add them? >> >>code like this: >> >> Private Sub grdAI_ItemDataBound(ByVal sender As >> >Object, >> >>ByVal e As >> >>System.Web.UI.WebControls.DataGridItemEventArg s) >> Handles >> >>grdAI.ItemDataBound >> >> Dim i As Integer >> >> Dim plcAI As PlaceHolder = CType >> >>(e.Item.FindControl("plcAI"), PlaceHolder) >> >> >> >> If Not plcAI Is Nothing Then >> >> Dim dr As DataRowView = CType >> >>(e.Item.DataItem, DataRowView) >> >> Select Case CInt(dr("FieldType")) >> >> Case 6 'ListView type >> >> Dim ddlAI As New DropDownList >> >> ddlAI.ID = "ddlAI" >> >> >> >> ddlAI.Items.Add("Big") >> >> ddlAI.Items.Add("Small") >> >> >> >> plcAI.Controls.Add(ddlAI) >> >> >> >> >> >> Case Else >> >> Dim txt As New TextBox >> >> txt.Text = "" >> >> plcAI.Controls.Add(txt) >> >> End Select >> >> End If >> >> >> >> End Sub >> >> >> >>>-----Original Message----- >> >>>On postback you'll need to re-add the controls >> >>> >> >>>Karl >> >>> >> >>>"Karl" <none> wrote in message >> >>news:eB**************@TK2MSFTNGP12.phx.gbl... >> >>>> What's null, plcAI or ddl? >> >>>> >> >>>> Karl >> >>>> >> >>>> "Julia Hu" <h6**@yahoo.ca> wrote in message >> >>>> news:ba****************************@phx.gbl... >> >>>> > Karl, >> >>>> > The code works. And now I need to retrieve
the >> data >> >>in >> >>>> > the dropdownlist which embeded in the placeholder >> >>>> > control. The following is my code does this, >> >however >> >>it >> >>>> > returns nothing. >> >>>> > >> >>>> > plcAI = CType(grid.Items(i).Cells (1).FindControl >> >>>> > ("plcAI"), PlaceHolder) >> >>>> > Dim ddl As DropDownList = CType (plcAI.FindControl >> >>>> > ("ddlAI"), DropDownList) >> >>>> > >> >>>> > thanks again >> >>>> > >> >>>> > >-----Original Message----- >> >>>> > >Julia, >> >>>> > >Try something like this: >> >>>> > > >> >>>> > ><asp:TemplateColumn HeaderText="Hotel Type"> >> >>>> > > <ItemTemplate> >> >>>> > > <asp:PlaceHolder ID="plc" Runat="server" /> >> >>>> > > </ItemTemplate> >> >>>> > ></asp:TemplateColumn> >> >>>> > > >> >>>> > >I'm not sure if you are using c# or vb.net,
and >> >>what you >> >>>> > are binding too, >> >>>> > >but assuming you are in vb.net and binding
to a >> >>>> > dataset/table, your >> >>>> > >ItemDatabound event should look something
like: >> >>>> > > >> >>>> > > Private Sub Grid_ItemDataBound(ByVal
sender As >> >>>> > Object, ByVal e As >> >>>> > >DataGridItemEventArgs) Handles grid.ItemDataBound >> >>>> > > If e.Item.ItemType = ListItemType.Item >> OrElse >> >>>> > e.Item.ItemType = >> >>>> > >ListItemType.AlternatingItem Then >> >>>> > > Dim plc As PlaceHolder = CType >> >>(e.Item.FindControl >> >>>> > ("plc"), PlaceHolder) >> >>>> > > If Not plc Is Nothing Then >> >>>> > > Dim dr As DataRowView = CType >> >>>> > (e.Item.DataItem, DataRowView) >> >>>> > > Select Case CInt(dr("type")) >> >>>> > > Case 1 >> >>>> > > Dim txt As New TextBox >> >>>> > > txt.Text = CStr(dr
("value")) >> >>>> > > plc.Controls.Add(txt) >> >>>> > > Case 2 >> >>>> > > Dim ddl As New
DropDownList >> >>>> > > plc.Controls.Add(ddl) >> >>>> > > End Select >> >>>> > > End If >> >>>> > > End If >> >>>> > > End Sub >> >>>> > > >> >>>> > >As you can see, we try to find the
placeholder >> >>contorl, >> >>>> > if it exists, we get >> >>>> > >a reference to the current row we are
using, we >> >can >> >>use >> >>>> > the values in the >> >>>> > >row (here, I used a mythical "Type" column)
to >> >>figure >> >>>> > out what type of >> >>>> > >control goes into the placeholder. >> >>>> > > >> >>>> > >Karl >> >>>> > > >> >>>> > >"Julia Hu" <h6**@yahoo.ca> wrote in message >> >>>> > >news:a8cd01c48786$4044e1c0
$a*******@phx.gbl... >> >>>> > >> Hi, >> >>>> > >> I have a datagrid, and in different rows I need >> >to >> >>>> > >> programmatically bind different type of >> controls >> >>and >> >>>> > load >> >>>> > >> data into these controls. For example,in
the >> >>first row >> >>>> > I >> >>>> > >> need to bind data into a textbox, and in
the >> >>second >> >>>> > row I >> >>>> > >> need to bind data into a dropdownlist...It all >> >>depends >> >>>> > on >> >>>> > >> the data I select from the database. >> >>>> > >> >> >>>> > >> I cannot use TemplateColumn because it
has to >> be >> >>the >> >>>> > same >> >>>> > >> type of control for one column. >> >>>> > >> >> >>>> > >> Thanks a lot, >> >>>> > >> >> >>>> > >> Julia >> >>>> > > >> >>>> > > >> >>>> > >. >> >>>> > > >> >>>> >> >>>> >> >>> >> >>> >> >>>. >> >>> >> >>. >> >> >> >. >> > > > >. >
.
if you check the details from this thread my email address is there (with a
bunch of REMOVEs) 'cuz I'm at home..but it's better to do is on here, might
help other people :)
karl
"Julia Hu" <h6**@yahoo.ca> wrote in message
news:bc****************************@phx.gbl... Thank you very much for your help! I probably will have questions about this PlaceHolder control in the near future, and I'd like to keep this thread going and hope you can give me some advice. I guess this is the only way to contact you directly 'cuz I don't have your email address.
Regards, Julia
-----Original Message----- it isn't an extra call if you cache the data...which is obviously somethingyou should consider at this point.
I believe that the id's won't change if the structure is the same, and youspecify the same ID for the ones you have control of.
Page_PreRender I believe so, but remember that your placeholder won't existuntil AFTER you bind the data to the grid. So before you do anything inpage_load you need your grid to be bound to it's source. Unless youabsolutely need the UI re-constructed after you post, I'd really recommendyou try and get away with the Request.Form. You might also have lucksearching for similar solution *dynamically added controls* or something. Finally, if you post again to this newsgroup in a new
thread, I won't reply,so you might get the input of someone else and find a better answer (I say Iwon't reply 'cuz if the other helpers are like me, they rarely reply if theysee that a post has a reply). Of course we can keep this thread going :) Karl
"Julia Hu" <an*******@discussions.microsoft.com> wrote
in messagenews:b8****************************@phx.gbl... Yes,just one more database call. I still have 2 questions: First,the UniqueID will never change if I keep the same columns structure in the datagrid? Second,if I use your 2nd solution to reload data,can I put in Page_PreRender instead of Page_Load? And can I still use the FindControl method to find "plc" and "ddl" like this plcAI = CType(grid.Items(i).Cells(1).FindControl ("plcAI"), PlaceHolder) Dim ddl As DropDownList = CType(plcAI.FindControl ("ddlAI"), DropDownList) ??
thank you very much
>-----Original Message----- >You can't directly....this gets uglier, doesn't it? If you rebuild you can, >if you don't you just have access to the value...although from the value you >can obvious get the text either by hitting your database or cache.. > >Karl > >"Julia Hu" <an*******@discussions.microsoft.com> wrote in message >news:bc****************************@phx.gbl... >> I tried both ClientID and UniqueID and the UniqueID >> works!! I got the SelectedValue, and how can I get the >> SelectedText?? >> >> >-----Original Message----- >> >If I reload controls again in postback, the selected >> item >> >of the dropdownlist will be lost. How do I keep it? >> > >> > >> >>-----Original Message----- >> >>As you told me, I loaded controls in ItemDataBound >> >event, >> >>and how can I re-add them? >> >>code like this: >> >> Private Sub grdAI_ItemDataBound(ByVal sender As >> >Object, >> >>ByVal e As >> >>System.Web.UI.WebControls.DataGridItemEventArg s) >> Handles >> >>grdAI.ItemDataBound >> >> Dim i As Integer >> >> Dim plcAI As PlaceHolder = CType >> >>(e.Item.FindControl("plcAI"), PlaceHolder) >> >> >> >> If Not plcAI Is Nothing Then >> >> Dim dr As DataRowView = CType >> >>(e.Item.DataItem, DataRowView) >> >> Select Case CInt(dr("FieldType")) >> >> Case 6 'ListView type >> >> Dim ddlAI As New DropDownList >> >> ddlAI.ID = "ddlAI" >> >> >> >> ddlAI.Items.Add("Big") >> >> ddlAI.Items.Add("Small") >> >> >> >> plcAI.Controls.Add(ddlAI) >> >> >> >> >> >> Case Else >> >> Dim txt As New TextBox >> >> txt.Text = "" >> >> plcAI.Controls.Add(txt) >> >> End Select >> >> End If >> >> >> >> End Sub >> >> >> >>>-----Original Message----- >> >>>On postback you'll need to re-add the controls >> >>> >> >>>Karl >> >>> >> >>>"Karl" <none> wrote in message >> >>news:eB**************@TK2MSFTNGP12.phx.gbl... >> >>>> What's null, plcAI or ddl? >> >>>> >> >>>> Karl >> >>>> >> >>>> "Julia Hu" <h6**@yahoo.ca> wrote in message >> >>>> news:ba****************************@phx.gbl... >> >>>> > Karl, >> >>>> > The code works. And now I need to retrieve the >> data >> >>in >> >>>> > the dropdownlist which embeded in the placeholder >> >>>> > control. The following is my code does this, >> >however >> >>it >> >>>> > returns nothing. >> >>>> > >> >>>> > plcAI = CType(grid.Items(i).Cells (1).FindControl >> >>>> > ("plcAI"), PlaceHolder) >> >>>> > Dim ddl As DropDownList = CType (plcAI.FindControl >> >>>> > ("ddlAI"), DropDownList) >> >>>> > >> >>>> > thanks again >> >>>> > >> >>>> > >-----Original Message----- >> >>>> > >Julia, >> >>>> > >Try something like this: >> >>>> > > >> >>>> > ><asp:TemplateColumn HeaderText="Hotel Type"> >> >>>> > > <ItemTemplate> >> >>>> > > <asp:PlaceHolder ID="plc" Runat="server" /> >> >>>> > > </ItemTemplate> >> >>>> > ></asp:TemplateColumn> >> >>>> > > >> >>>> > >I'm not sure if you are using c# or vb.net, and >> >>what you >> >>>> > are binding too, >> >>>> > >but assuming you are in vb.net and binding to a >> >>>> > dataset/table, your >> >>>> > >ItemDatabound event should look something like: >> >>>> > > >> >>>> > > Private Sub Grid_ItemDataBound(ByVal sender As >> >>>> > Object, ByVal e As >> >>>> > >DataGridItemEventArgs) Handles grid.ItemDataBound >> >>>> > > If e.Item.ItemType = ListItemType.Item >> OrElse >> >>>> > e.Item.ItemType = >> >>>> > >ListItemType.AlternatingItem Then >> >>>> > > Dim plc As PlaceHolder = CType >> >>(e.Item.FindControl >> >>>> > ("plc"), PlaceHolder) >> >>>> > > If Not plc Is Nothing Then >> >>>> > > Dim dr As DataRowView = CType >> >>>> > (e.Item.DataItem, DataRowView) >> >>>> > > Select Case CInt(dr("type")) >> >>>> > > Case 1 >> >>>> > > Dim txt As New TextBox >> >>>> > > txt.Text = CStr(dr ("value")) >> >>>> > > plc.Controls.Add(txt) >> >>>> > > Case 2 >> >>>> > > Dim ddl As New DropDownList >> >>>> > > plc.Controls.Add(ddl) >> >>>> > > End Select >> >>>> > > End If >> >>>> > > End If >> >>>> > > End Sub >> >>>> > > >> >>>> > >As you can see, we try to find the placeholder >> >>contorl, >> >>>> > if it exists, we get >> >>>> > >a reference to the current row we are using, we >> >can >> >>use >> >>>> > the values in the >> >>>> > >row (here, I used a mythical "Type" column) to >> >>figure >> >>>> > out what type of >> >>>> > >control goes into the placeholder. >> >>>> > > >> >>>> > >Karl >> >>>> > > >> >>>> > >"Julia Hu" <h6**@yahoo.ca> wrote in message >> >>>> > >news:a8cd01c48786$4044e1c0 $a*******@phx.gbl... >> >>>> > >> Hi, >> >>>> > >> I have a datagrid, and in different rows I need >> >to >> >>>> > >> programmatically bind different type of >> controls >> >>and >> >>>> > load >> >>>> > >> data into these controls. For example,in the >> >>first row >> >>>> > I >> >>>> > >> need to bind data into a textbox, and in the >> >>second >> >>>> > row I >> >>>> > >> need to bind data into a dropdownlist...It all >> >>depends >> >>>> > on >> >>>> > >> the data I select from the database. >> >>>> > >> >> >>>> > >> I cannot use TemplateColumn because it has to >> be >> >>the >> >>>> > same >> >>>> > >> type of control for one column. >> >>>> > >> >> >>>> > >> Thanks a lot, >> >>>> > >> >> >>>> > >> Julia >> >>>> > > >> >>>> > > >> >>>> > >. >> >>>> > > >> >>>> >> >>>> >> >>> >> >>> >> >>>. >> >>> >> >>. >> >> >> >. >> > > > >. >
.
As you told me,the UniqueID is composed of grid ID,row ID
and ddl ID,but why the row ID is always the actual row +
1? The grid doesn't have a header. For example,the ddl in
the first row of my grid is:
grdAiEditGrid:grdAI:_ctl2:ddlAI
thanks -----Original Message----- if you check the details from this thread my email
address is there (with abunch of REMOVEs) 'cuz I'm at home..but it's better to
do is on here, mighthelp other people :)
karl
"Julia Hu" <h6**@yahoo.ca> wrote in message news:bc****************************@phx.gbl... Thank you very much for your help! I probably will have questions about this PlaceHolder control in the near future, and I'd like to keep this thread going and hope you can give me some advice. I guess this is the only way to contact you
directly 'cuz I don't have your email address.
Regards, Julia
>-----Original Message----- >it isn't an extra call if you cache the data...which
is obviously something >you should consider at this point. > >I believe that the id's won't change if the structure
is the same, and you >specify the same ID for the ones you have control of. > >Page_PreRender I believe so, but remember that your placeholder won't exist >until AFTER you bind the data to the grid. So before you do anything in >page_load you need your grid to be bound to it's source. Unless you >absolutely need the UI re-constructed after you post, I'd really recommend >you try and get away with the Request.Form. You might also have luck >searching for similar solution *dynamically added controls* or something. > >Finally, if you post again to this newsgroup in a new thread, I won't reply, >so you might get the input of someone else and find a better answer (I say I >won't reply 'cuz if the other helpers are like me,
they rarely reply if they >see that a post has a reply). Of course we can keep this thread going :) > >Karl > >"Julia Hu" <an*******@discussions.microsoft.com> wrote in message >news:b8****************************@phx.gbl... >> Yes,just one more database call. >> I still have 2 questions: >> First,the UniqueID will never change if I keep the
same >> columns structure in the datagrid? >> Second,if I use your 2nd solution to reload
data,can I >> put in Page_PreRender instead of Page_Load? And can
I >> still use the FindControl method to find "plc" and "ddl" >> like this >> plcAI = CType(grid.Items(i).Cells(1).FindControl >> ("plcAI"), PlaceHolder) >> Dim ddl As DropDownList = CType(plcAI.FindControl >> ("ddlAI"), DropDownList) ?? >> >> thank you very much >> >> >> >-----Original Message----- >> >You can't directly....this gets uglier, doesn't it? If >> you rebuild you can, >> >if you don't you just have access to the >> value...although from the value you >> >can obvious get the text either by hitting your database >> or cache.. >> > >> >Karl >> > >> >"Julia Hu" <an*******@discussions.microsoft.com>
wrote >> in message >> >news:bc****************************@phx.gbl... >> >> I tried both ClientID and UniqueID and the
UniqueID >> >> works!! I got the SelectedValue, and how can I
get the >> >> SelectedText?? >> >> >> >> >-----Original Message----- >> >> >If I reload controls again in postback, the selected >> >> item >> >> >of the dropdownlist will be lost. How do I keep
it? >> >> > >> >> > >> >> >>-----Original Message----- >> >> >>As you told me, I loaded controls in
ItemDataBound >> >> >event, >> >> >>and how can I re-add them? >> >> >>code like this: >> >> >> Private Sub grdAI_ItemDataBound(ByVal sender
As >> >> >Object, >> >> >>ByVal e As >> >> System.Web.UI.WebControls.DataGridItemEventArg s) >> >> Handles >> >> >>grdAI.ItemDataBound >> >> >> Dim i As Integer >> >> >> Dim plcAI As PlaceHolder = CType >> >> >>(e.Item.FindControl("plcAI"), PlaceHolder) >> >> >> >> >> >> If Not plcAI Is Nothing Then >> >> >> Dim dr As DataRowView = CType >> >> >>(e.Item.DataItem, DataRowView) >> >> >> Select Case CInt(dr("FieldType")) >> >> >> Case 6 'ListView type >> >> >> Dim ddlAI As New
DropDownList >> >> >> ddlAI.ID = "ddlAI" >> >> >> >> >> >> ddlAI.Items.Add("Big") >> >> >> ddlAI.Items.Add("Small") >> >> >> >> >> >> plcAI.Controls.Add(ddlAI) >> >> >> >> >> >> >> >> >> Case Else >> >> >> Dim txt As New TextBox >> >> >> txt.Text = "" >> >> >> plcAI.Controls.Add(txt) >> >> >> End Select >> >> >> End If >> >> >> >> >> >> End Sub >> >> >> >> >> >>>-----Original Message----- >> >> >>>On postback you'll need to re-add the controls >> >> >>> >> >> >>>Karl >> >> >>> >> >> >>>"Karl" <none> wrote in message >> >> >>news:eB**************@TK2MSFTNGP12.phx.gbl... >> >> >>>> What's null, plcAI or ddl? >> >> >>>> >> >> >>>> Karl >> >> >>>> >> >> >>>> "Julia Hu" <h6**@yahoo.ca> wrote in message >> >> >>>> news:ba9401c48927$777a4c50
$a*******@phx.gbl... >> >> >>>> > Karl, >> >> >>>> > The code works. And now I need to retrieve the >> >> data >> >> >>in >> >> >>>> > the dropdownlist which embeded in the >> placeholder >> >> >>>> > control. The following is my code does
this, >> >> >however >> >> >>it >> >> >>>> > returns nothing. >> >> >>>> > >> >> >>>> > plcAI = CType(grid.Items(i).Cells >> (1).FindControl >> >> >>>> > ("plcAI"), PlaceHolder) >> >> >>>> > Dim ddl As DropDownList = CType >> (plcAI.FindControl >> >> >>>> > ("ddlAI"), DropDownList) >> >> >>>> > >> >> >>>> > thanks again >> >> >>>> > >> >> >>>> > >-----Original Message----- >> >> >>>> > >Julia, >> >> >>>> > >Try something like this: >> >> >>>> > > >> >> >>>> > ><asp:TemplateColumn HeaderText="Hotel
Type"> >> >> >>>> > > <ItemTemplate> >> >> >>>> > > <asp:PlaceHolder ID="plc" >> Runat="server" /> >> >> >>>> > > </ItemTemplate> >> >> >>>> > ></asp:TemplateColumn> >> >> >>>> > > >> >> >>>> > >I'm not sure if you are using c# or
vb.net, and >> >> >>what you >> >> >>>> > are binding too, >> >> >>>> > >but assuming you are in vb.net and
binding to a >> >> >>>> > dataset/table, your >> >> >>>> > >ItemDatabound event should look something like: >> >> >>>> > > >> >> >>>> > > Private Sub Grid_ItemDataBound(ByVal sender >> As >> >> >>>> > Object, ByVal e As >> >> >>>> > >DataGridItemEventArgs) Handles >> grid.ItemDataBound >> >> >>>> > > If e.Item.ItemType =
ListItemType.Item >> >> OrElse >> >> >>>> > e.Item.ItemType = >> >> >>>> > >ListItemType.AlternatingItem Then >> >> >>>> > > Dim plc As PlaceHolder = CType >> >> >>(e.Item.FindControl >> >> >>>> > ("plc"), PlaceHolder) >> >> >>>> > > If Not plc Is Nothing Then >> >> >>>> > > Dim dr As DataRowView = CType >> >> >>>> > (e.Item.DataItem, DataRowView) >> >> >>>> > > Select Case CInt(dr("type")) >> >> >>>> > > Case 1 >> >> >>>> > > Dim txt As New TextBox >> >> >>>> > > txt.Text = CStr(dr ("value")) >> >> >>>> > > plc.Controls.Add(txt) >> >> >>>> > > Case 2 >> >> >>>> > > Dim ddl As New DropDownList >> >> >>>> > > plc.Controls.Add(ddl) >> >> >>>> > > End Select >> >> >>>> > > End If >> >> >>>> > > End If >> >> >>>> > > End Sub >> >> >>>> > > >> >> >>>> > >As you can see, we try to find the placeholder >> >> >>contorl, >> >> >>>> > if it exists, we get >> >> >>>> > >a reference to the current row we are using, we >> >> >can >> >> >>use >> >> >>>> > the values in the >> >> >>>> > >row (here, I used a mythical "Type"
column) to >> >> >>figure >> >> >>>> > out what type of >> >> >>>> > >control goes into the placeholder. >> >> >>>> > > >> >> >>>> > >Karl >> >> >>>> > > >> >> >>>> > >"Julia Hu" <h6**@yahoo.ca> wrote in
message >> >> >>>> > >news:a8cd01c48786$4044e1c0 $a*******@phx.gbl... >> >> >>>> > >> Hi, >> >> >>>> > >> I have a datagrid, and in different
rows I >> need >> >> >to >> >> >>>> > >> programmatically bind different type of >> >> controls >> >> >>and >> >> >>>> > load >> >> >>>> > >> data into these controls. For
example,in the >> >> >>first row >> >> >>>> > I >> >> >>>> > >> need to bind data into a textbox, and
in the >> >> >>second >> >> >>>> > row I >> >> >>>> > >> need to bind data into a
dropdownlist...It >> all >> >> >>depends >> >> >>>> > on >> >> >>>> > >> the data I select from the database. >> >> >>>> > >> >> >> >>>> > >> I cannot use TemplateColumn because it has to >> >> be >> >> >>the >> >> >>>> > same >> >> >>>> > >> type of control for one column. >> >> >>>> > >> >> >> >>>> > >> Thanks a lot, >> >> >>>> > >> >> >> >>>> > >> Julia >> >> >>>> > > >> >> >>>> > > >> >> >>>> > >. >> >> >>>> > > >> >> >>>> >> >> >>>> >> >> >>> >> >> >>> >> >> >>>. >> >> >>> >> >> >>. >> >> >> >> >> >. >> >> > >> > >> > >> >. >> > > > >. >
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stanley J Mroczek |
last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ?
<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option...
|
by: Stanley J Mroczek |
last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid.
I tried to use OnDataBinding and loading the droplist in subroutine "loaddd".
I get this error Object reference not set...
|
by: Stanley J Mroczek |
last post by:
I am trying to load a dropdownlist in VB when the edit is clicked in a
datagrid. How do i call Sub loaddd to load the dropdownlist
<asp:TemplateColumn runat="server" HeaderText="Id Type Option"...
|
by: John Kirksey |
last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |