473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help Needed -- Datalist linkbutton

Hi Folks,
Suppose I have two link button on a page (say lnkBtn1 and
lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically
created control. And On the click event of the lnkBtn2 I have to add a
datalist control.
Using this datalist control I should be able to add edit, modify
and cancel the items listed in this control.

Here is how I designed. I used placeholder to add the controls dynamically
to the page on the click events of the buttons. Everything seems to be
working fine until I click on the edit button of the datalist control. This
control disappears and the corresponding event handler is not raised.

Can anyone help how to change my design to suit my needs.

Thanks
Bharat
Nov 18 '05 #1
10 2808
Bharat,
If I understand correctly, you are in a tricky situation....but its
something worth clearly understanding and learning.

Basically what's happening (or rather what isn't happening) is that you need
to _reload_ the controls when the edit button is clicked. What you have is
this:

Link Button 1 click -->
Control 1 loaded -->
Edit Clicked -->
NOTHING

What you need is this:

Link button 1 clicked -->
Control 1 loaded -->
Edit Clicked -->
Control 1 Loaded -->
Woohoooo

One of the easiest ways to achieve this is to keep the name of the control
in viewstate object. This will let you know which control to reload when
the edit button is clicked:

Link button 1 clicked -->
Control 1 loaded -->
Control name/path stored in viewstate -->
Edit Clicked -->
Control name/path retrieved from viewstate -->
Control 1 Loaded -->
Woohoooo

Hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi Folks,
Suppose I have two link button on a page (say lnkBtn1 and
lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically
created control. And On the click event of the lnkBtn2 I have to add a
datalist control.
Using this datalist control I should be able to add edit, modify
and cancel the items listed in this control.

Here is how I designed. I used placeholder to add the controls dynamically
to the page on the click events of the buttons. Everything seems to be
working fine until I click on the edit button of the datalist control. This control disappears and the corresponding event handler is not raised.

Can anyone help how to change my design to suit my needs.

Thanks
Bharat

Nov 18 '05 #2
Karl,
I thought I figured it out but now I am facing a different kind of
problem. When I click on edit of the datalist the controls defined in the
edit control show up as they should be. I change some values and then click
update. Update event is never raised.

What can casue this problem. I am loading the datalist into a placeholder
each each round trip to the server since I load this datalist dynamically.

What could be the problem.

Thanks
Bharat

"Karl" wrote:
Bharat,
If I understand correctly, you are in a tricky situation....but its
something worth clearly understanding and learning.

Basically what's happening (or rather what isn't happening) is that you need
to _reload_ the controls when the edit button is clicked. What you have is
this:

Link Button 1 click -->
Control 1 loaded -->
Edit Clicked -->
NOTHING

What you need is this:

Link button 1 clicked -->
Control 1 loaded -->
Edit Clicked -->
Control 1 Loaded -->
Woohoooo

One of the easiest ways to achieve this is to keep the name of the control
in viewstate object. This will let you know which control to reload when
the edit button is clicked:

Link button 1 clicked -->
Control 1 loaded -->
Control name/path stored in viewstate -->
Edit Clicked -->
Control name/path retrieved from viewstate -->
Control 1 Loaded -->
Woohoooo

Hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi Folks,
Suppose I have two link button on a page (say lnkBtn1 and
lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically
created control. And On the click event of the lnkBtn2 I have to add a
datalist control.
Using this datalist control I should be able to add edit, modify
and cancel the items listed in this control.

Here is how I designed. I used placeholder to add the controls dynamically
to the page on the click events of the buttons. Everything seems to be
working fine until I click on the edit button of the datalist control.

This
control disappears and the corresponding event handler is not raised.

Can anyone help how to change my design to suit my needs.

Thanks
Bharat


Nov 18 '05 #3
not 100%...are you rebinding the datalist each time? You should only bind
it the first time I think...

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
Karl,
I thought I figured it out but now I am facing a different kind of
problem. When I click on edit of the datalist the controls defined in the
edit control show up as they should be. I change some values and then click update. Update event is never raised.

What can casue this problem. I am loading the datalist into a placeholder
each each round trip to the server since I load this datalist dynamically.

What could be the problem.

Thanks
Bharat

"Karl" wrote:
Bharat,
If I understand correctly, you are in a tricky situation....but its
something worth clearly understanding and learning.

Basically what's happening (or rather what isn't happening) is that you need to _reload_ the controls when the edit button is clicked. What you have is this:

Link Button 1 click -->
Control 1 loaded -->
Edit Clicked -->
NOTHING

What you need is this:

Link button 1 clicked -->
Control 1 loaded -->
Edit Clicked -->
Control 1 Loaded -->
Woohoooo

One of the easiest ways to achieve this is to keep the name of the control in viewstate object. This will let you know which control to reload when the edit button is clicked:

Link button 1 clicked -->
Control 1 loaded -->
Control name/path stored in viewstate -->
Edit Clicked -->
Control name/path retrieved from viewstate -->
Control 1 Loaded -->
Woohoooo

Hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi Folks,
Suppose I have two link button on a page (say lnkBtn1 and
lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I have to add a
datalist control.
Using this datalist control I should be able to add edit, modify and cancel the items listed in this control.

Here is how I designed. I used placeholder to add the controls dynamically to the page on the click events of the buttons. Everything seems to be
working fine until I click on the edit button of the datalist control.

This
control disappears and the corresponding event handler is not raised.

Can anyone help how to change my design to suit my needs.

Thanks
Bharat


Nov 18 '05 #4
Hi karl,
Yeah I was rebinding the datalist in each roundtrip. But the problem is if
I don't rebind, the datalist control doesnot show up. So how do I do this.

Any Help??

Thanks
Bharat
"Karl" wrote:
not 100%...are you rebinding the datalist each time? You should only bind
it the first time I think...

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
Karl,
I thought I figured it out but now I am facing a different kind of
problem. When I click on edit of the datalist the controls defined in the
edit control show up as they should be. I change some values and then

click
update. Update event is never raised.

What can casue this problem. I am loading the datalist into a placeholder
each each round trip to the server since I load this datalist dynamically.

What could be the problem.

Thanks
Bharat

"Karl" wrote:
Bharat,
If I understand correctly, you are in a tricky situation....but its
something worth clearly understanding and learning.

Basically what's happening (or rather what isn't happening) is that you need to _reload_ the controls when the edit button is clicked. What you have is this:

Link Button 1 click -->
Control 1 loaded -->
Edit Clicked -->
NOTHING

What you need is this:

Link button 1 clicked -->
Control 1 loaded -->
Edit Clicked -->
Control 1 Loaded -->
Woohoooo

One of the easiest ways to achieve this is to keep the name of the control in viewstate object. This will let you know which control to reload when the edit button is clicked:

Link button 1 clicked -->
Control 1 loaded -->
Control name/path stored in viewstate -->
Edit Clicked -->
Control name/path retrieved from viewstate -->
Control 1 Loaded -->
Woohoooo

Hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
> Hi Folks,
> Suppose I have two link button on a page (say lnkBtn1 and
> lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically > created control. And On the click event of the lnkBtn2 I have to add a
> datalist control.
> Using this datalist control I should be able to add edit, modify > and cancel the items listed in this control.
>
> Here is how I designed. I used placeholder to add the controls dynamically > to the page on the click events of the buttons. Everything seems to be
> working fine until I click on the edit button of the datalist control.
This
> control disappears and the corresponding event handler is not raised.
>
> Can anyone help how to change my design to suit my needs.
>
> Thanks
> Bharat


Nov 18 '05 #5
I think I need more information...where's the update button located? Is it
on the same control as the datagrid? it it a button inside the datagrid
(like the edit button).

Perhaps additional code would be useful to me..

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi karl,
Yeah I was rebinding the datalist in each roundtrip. But the problem is if I don't rebind, the datalist control doesnot show up. So how do I do this.

Any Help??

Thanks
Bharat
"Karl" wrote:
not 100%...are you rebinding the datalist each time? You should only bind it the first time I think...

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
Karl,
I thought I figured it out but now I am facing a different kind of problem. When I click on edit of the datalist the controls defined in the edit control show up as they should be. I change some values and then

click
update. Update event is never raised.

What can casue this problem. I am loading the datalist into a placeholder each each round trip to the server since I load this datalist dynamically.
What could be the problem.

Thanks
Bharat

"Karl" wrote:

> Bharat,
> If I understand correctly, you are in a tricky situation....but its
> something worth clearly understanding and learning.
>
> Basically what's happening (or rather what isn't happening) is that you
need
> to _reload_ the controls when the edit button is clicked. What you
have is
> this:
>
> Link Button 1 click -->
> Control 1 loaded -->
> Edit Clicked -->
> NOTHING
>
> What you need is this:
>
> Link button 1 clicked -->
> Control 1 loaded -->
> Edit Clicked -->
> Control 1 Loaded -->
> Woohoooo
>
> One of the easiest ways to achieve this is to keep the name of the

control
> in viewstate object. This will let you know which control to reload

when
> the edit button is clicked:
>
> Link button 1 clicked -->
> Control 1 loaded -->
> Control name/path stored in viewstate -->
> Edit Clicked -->
> Control name/path retrieved from viewstate -->
> Control 1 Loaded -->
> Woohoooo
>
> Hope that helps.
>
> Karl
>
> "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> news:4E**********************************@microsof t.com...
> > Hi Folks,
> > Suppose I have two link button on a page (say lnkBtn1
and > > lnkBtn2). On the click event of the lnkbtn1 I have to add a

dynamically
> > created control. And On the click event of the lnkBtn2 I have to add a > > datalist control.
> > Using this datalist control I should be able to add edit, modify
> > and cancel the items listed in this control.
> >
> > Here is how I designed. I used placeholder to add the controls

dynamically
> > to the page on the click events of the buttons. Everything seems

to be > > working fine until I click on the edit button of the datalist control. > This
> > control disappears and the corresponding event handler is not raised. > >
> > Can anyone help how to change my design to suit my needs.
> >
> > Thanks
> > Bharat
>
>
>


Nov 18 '05 #6
Yeah update button is in the datalist like the edit button. Here is the
control description. When I place this directly on the form the update event
is raised. Only when I load this datalist control into a placeholder all
problems rise. If I don't rebind on every trip to server the control all
together dissapears.
<asp:datalist id="ddlMonthlyRecurring" runat="server" Font-Size="12pt"
BorderColor="black" BorderWidth="2"
GridLines="Both" CellPadding="5" CellSpacing="0" Font-Name="Verdana"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="aqua" OnEditCommand="ddlMonthlyRecurring_EditCommand"
OnUpdateCommand="ddlMonthlyRecurring_UpdateCommand "
OnCancelCommand="ddlMonthlyRecurring_CancelCommand "
Width="500px">
<HeaderTemplate>
Monthly Recurring Bills
</HeaderTemplate>
<EditItemStyle Font-Size="12px" BackColor="LemonChiffon"></EditItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<asp:LinkButton id="button1" runat="server" Text="Edit" Width="100px"
CommandName="edit"></asp:LinkButton>
<asp:Label id=lblBillName runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>' Width="150px">
</asp:Label>
<asp:Label id=lblBillValue runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>' Width="150px">
</asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="16px" BackColor="#AAAADD"></HeaderStyle>
<EditItemTemplate>
<asp:Label id="Textbox1" runat="server" Text='Bill Name:'></asp:Label>
<asp:TextBox id="Label_BillName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:Label id="Label_BillValue" runat="server" Text='Bill
Value:'></asp:Label>
<asp:TextBox id=Text1 runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:LinkButton id="button2" runat="server" Text="Update"
CommandName="update" Width="30px"></asp:LinkButton>
<asp:LinkButton id="button3" runat="server" Text="Cancel"
CommandName="cancel" Width="30px"></asp:LinkButton>
</EditItemTemplate>
</asp:datalist>
Thanks
Bharat

"Karl" wrote:
I think I need more information...where's the update button located? Is it
on the same control as the datagrid? it it a button inside the datagrid
(like the edit button).

Perhaps additional code would be useful to me..

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi karl,
Yeah I was rebinding the datalist in each roundtrip. But the problem is

if
I don't rebind, the datalist control doesnot show up. So how do I do this.

Any Help??

Thanks
Bharat
"Karl" wrote:
not 100%...are you rebinding the datalist each time? You should only bind it the first time I think...

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
> Karl,
> I thought I figured it out but now I am facing a different kind of > problem. When I click on edit of the datalist the controls defined in the > edit control show up as they should be. I change some values and then
click
> update. Update event is never raised.
>
> What can casue this problem. I am loading the datalist into a placeholder > each each round trip to the server since I load this datalist dynamically. >
> What could be the problem.
>
> Thanks
> Bharat
>
>
>
> "Karl" wrote:
>
> > Bharat,
> > If I understand correctly, you are in a tricky situation....but its
> > something worth clearly understanding and learning.
> >
> > Basically what's happening (or rather what isn't happening) is that you need
> > to _reload_ the controls when the edit button is clicked. What you have is
> > this:
> >
> > Link Button 1 click -->
> > Control 1 loaded -->
> > Edit Clicked -->
> > NOTHING
> >
> > What you need is this:
> >
> > Link button 1 clicked -->
> > Control 1 loaded -->
> > Edit Clicked -->
> > Control 1 Loaded -->
> > Woohoooo
> >
> > One of the easiest ways to achieve this is to keep the name of the
control
> > in viewstate object. This will let you know which control to reload
when
> > the edit button is clicked:
> >
> > Link button 1 clicked -->
> > Control 1 loaded -->
> > Control name/path stored in viewstate -->
> > Edit Clicked -->
> > Control name/path retrieved from viewstate -->
> > Control 1 Loaded -->
> > Woohoooo
> >
> > Hope that helps.
> >
> > Karl
> >
> > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > news:4E**********************************@microsof t.com...
> > > Hi Folks,
> > > Suppose I have two link button on a page (say lnkBtn1 and > > > lnkBtn2). On the click event of the lnkbtn1 I have to add a
dynamically
> > > created control. And On the click event of the lnkBtn2 I have to add a > > > datalist control.
> > > Using this datalist control I should be able to add edit, modify
> > > and cancel the items listed in this control.
> > >
> > > Here is how I designed. I used placeholder to add the controls
dynamically
> > > to the page on the click events of the buttons. Everything seems to be > > > working fine until I click on the edit button of the datalist control. > > This
> > > control disappears and the corresponding event handler is not raised. > > >
> > > Can anyone help how to change my design to suit my needs.
> > >
> > > Thanks
> > > Bharat
> >
> >
> >


Nov 18 '05 #7
Here's how I got it working, this is the codebehind for my usercontrol:

private void Page_Load(object sender, EventArgs e) {
if(!((WebForm1)Page).IsControlReloaded){
BindGrid();
}
}
private void BindGrid() {
DataTable dt = new DataTable();
dt.Columns.Add("BillName");
dt.Columns.Add("BillValue");
for (int i = 0; i < 5; i++){
DataRow dr = dt.NewRow();
dr[0] = 1*(i + 1);
dr[1] = 3*(i + 1);
dt.Rows.Add(dr);
}
grdUpload.DataSource = dt;
grdUpload.DataBind();
}
protected void ddlMonthlyRecurring_EditCommand(object sender,
DataListCommandEventArgs e) {
grdUpload.EditItemIndex = e.Item.ItemIndex;
BindGrid();

}
protected void ddlMonthlyRecurring_UpdateCommand(object sender,
DataListCommandEventArgs e) {
TextBox Label_BillName =
(TextBox)e.Item.FindControl("Label_BillName");
//do whatever
}

Now, the only tricky part is the code in the Page_Load. As you can see, it
used the isControlReloaded of the Page to see if this is an internal
postback (you can't simply use Page.IsPostBack because then it won't work
the first time around). This is what the WebForm1 page codebehind looks
like:

public bool IsControlReloaded = false;
protected LinkButton lnk;
protected PlaceHolder plc;
private void Page_Load(object sender, EventArgs e) {
string c = (string)ViewState["c"];
if (c != null){
isControlReloaded = true;
plc.Controls.Add(Page.LoadControl(c));
}
}
private void lnk_Click(object sender, EventArgs e) {
ViewState.Add("c", "u1.ascx");
plc.Controls.Add(Page.LoadControl("u1.ascx"));
}
I hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Yeah update button is in the datalist like the edit button. Here is the
control description. When I place this directly on the form the update event is raised. Only when I load this datalist control into a placeholder all
problems rise. If I don't rebind on every trip to server the control all
together dissapears.
<asp:datalist id="ddlMonthlyRecurring" runat="server" Font-Size="12pt"
BorderColor="black" BorderWidth="2"
GridLines="Both" CellPadding="5" CellSpacing="0" Font-Name="Verdana"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="aqua" OnEditCommand="ddlMonthlyRecurring_EditCommand" OnUpdateCommand="ddlMonthlyRecurring_UpdateCommand "
OnCancelCommand="ddlMonthlyRecurring_CancelCommand "
Width="500px">
<HeaderTemplate>
Monthly Recurring Bills
</HeaderTemplate>
<EditItemStyle Font-Size="12px" BackColor="LemonChiffon"></EditItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<asp:LinkButton id="button1" runat="server" Text="Edit" Width="100px"
CommandName="edit"></asp:LinkButton>
<asp:Label id=lblBillName runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>' Width="150px">
</asp:Label>
<asp:Label id=lblBillValue runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>' Width="150px">
</asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="16px" BackColor="#AAAADD"></HeaderStyle>
<EditItemTemplate>
<asp:Label id="Textbox1" runat="server" Text='Bill Name:'></asp:Label>
<asp:TextBox id="Label_BillName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:Label id="Label_BillValue" runat="server" Text='Bill
Value:'></asp:Label>
<asp:TextBox id=Text1 runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:LinkButton id="button2" runat="server" Text="Update"
CommandName="update" Width="30px"></asp:LinkButton>
<asp:LinkButton id="button3" runat="server" Text="Cancel"
CommandName="cancel" Width="30px"></asp:LinkButton>
</EditItemTemplate>
</asp:datalist>
Thanks
Bharat

"Karl" wrote:
I think I need more information...where's the update button located? Is it on the same control as the datagrid? it it a button inside the datagrid
(like the edit button).

Perhaps additional code would be useful to me..

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi karl,
Yeah I was rebinding the datalist in each roundtrip. But the problem is
if
I don't rebind, the datalist control doesnot show up. So how do I do
this.
Any Help??

Thanks
Bharat
"Karl" wrote:

> not 100%...are you rebinding the datalist each time? You should only bind
> it the first time I think...
>
> Karl
>
> "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> news:60**********************************@microsof t.com...
> > Karl,
> > I thought I figured it out but now I am facing a different
kind of
> > problem. When I click on edit of the datalist the controls defined
in the
> > edit control show up as they should be. I change some values and
then > click
> > update. Update event is never raised.
> >
> > What can casue this problem. I am loading the datalist into a

placeholder
> > each each round trip to the server since I load this datalist

dynamically.
> >
> > What could be the problem.
> >
> > Thanks
> > Bharat
> >
> >
> >
> > "Karl" wrote:
> >
> > > Bharat,
> > > If I understand correctly, you are in a tricky situation....but its > > > something worth clearly understanding and learning.
> > >
> > > Basically what's happening (or rather what isn't happening) is that you
> need
> > > to _reload_ the controls when the edit button is clicked. What
you have
> is
> > > this:
> > >
> > > Link Button 1 click -->
> > > Control 1 loaded -->
> > > Edit Clicked -->
> > > NOTHING
> > >
> > > What you need is this:
> > >
> > > Link button 1 clicked -->
> > > Control 1 loaded -->
> > > Edit Clicked -->
> > > Control 1 Loaded -->
> > > Woohoooo
> > >
> > > One of the easiest ways to achieve this is to keep the name of
the > control
> > > in viewstate object. This will let you know which control to reload > when
> > > the edit button is clicked:
> > >
> > > Link button 1 clicked -->
> > > Control 1 loaded -->
> > > Control name/path stored in viewstate -->
> > > Edit Clicked -->
> > > Control name/path retrieved from viewstate -->
> > > Control 1 Loaded -->
> > > Woohoooo
> > >
> > > Hope that helps.
> > >
> > > Karl
> > >
> > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > news:4E**********************************@microsof t.com...
> > > > Hi Folks,
> > > > Suppose I have two link button on a page (say

lnkBtn1 and
> > > > lnkBtn2). On the click event of the lnkbtn1 I have to add a
> dynamically
> > > > created control. And On the click event of the lnkBtn2 I have
to add a
> > > > datalist control.
> > > > Using this datalist control I should be able to add

edit,
> modify
> > > > and cancel the items listed in this control.
> > > >
> > > > Here is how I designed. I used placeholder to add the controls
> dynamically
> > > > to the page on the click events of the buttons. Everything
seems to be
> > > > working fine until I click on the edit button of the datalist

control.
> > > This
> > > > control disappears and the corresponding event handler is not

raised.
> > > >
> > > > Can anyone help how to change my design to suit my needs.
> > > >
> > > > Thanks
> > > > Bharat
> > >
> > >
> > >
>
>
>


Nov 18 '05 #8
Hi Karl,
Thankyou very much. I got it to work your way, yet there is one more
problem. Since I am using a placeholder to load the user controls on click
events of the link buttons. I had the enableviewstate property set to false
for the placeholder because I had to load different controls on click events
of those link buttons.
If I set the enableviewstate property to true then the place holder
can load the same type of controls that were loaded in the previous
roundtrip. For this reason I cannot load new controls into placeholder. If I
set to false I have to bind the datalist in the roundtrips to the server.
Then all the events trigerred on the datalist are lost.

How can I get around this and be able to load the only needed controls? Any
suggestions would be appretiated.

Thanks
Bharat
"Karl" wrote:
Here's how I got it working, this is the codebehind for my usercontrol:

private void Page_Load(object sender, EventArgs e) {
if(!((WebForm1)Page).IsControlReloaded){
BindGrid();
}
}
private void BindGrid() {
DataTable dt = new DataTable();
dt.Columns.Add("BillName");
dt.Columns.Add("BillValue");
for (int i = 0; i < 5; i++){
DataRow dr = dt.NewRow();
dr[0] = 1*(i + 1);
dr[1] = 3*(i + 1);
dt.Rows.Add(dr);
}
grdUpload.DataSource = dt;
grdUpload.DataBind();
}
protected void ddlMonthlyRecurring_EditCommand(object sender,
DataListCommandEventArgs e) {
grdUpload.EditItemIndex = e.Item.ItemIndex;
BindGrid();

}
protected void ddlMonthlyRecurring_UpdateCommand(object sender,
DataListCommandEventArgs e) {
TextBox Label_BillName =
(TextBox)e.Item.FindControl("Label_BillName");
//do whatever
}

Now, the only tricky part is the code in the Page_Load. As you can see, it
used the isControlReloaded of the Page to see if this is an internal
postback (you can't simply use Page.IsPostBack because then it won't work
the first time around). This is what the WebForm1 page codebehind looks
like:

public bool IsControlReloaded = false;
protected LinkButton lnk;
protected PlaceHolder plc;
private void Page_Load(object sender, EventArgs e) {
string c = (string)ViewState["c"];
if (c != null){
isControlReloaded = true;
plc.Controls.Add(Page.LoadControl(c));
}
}
private void lnk_Click(object sender, EventArgs e) {
ViewState.Add("c", "u1.ascx");
plc.Controls.Add(Page.LoadControl("u1.ascx"));
}
I hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Yeah update button is in the datalist like the edit button. Here is the
control description. When I place this directly on the form the update

event
is raised. Only when I load this datalist control into a placeholder all
problems rise. If I don't rebind on every trip to server the control all
together dissapears.
<asp:datalist id="ddlMonthlyRecurring" runat="server" Font-Size="12pt"
BorderColor="black" BorderWidth="2"
GridLines="Both" CellPadding="5" CellSpacing="0" Font-Name="Verdana"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="aqua"

OnEditCommand="ddlMonthlyRecurring_EditCommand"
OnUpdateCommand="ddlMonthlyRecurring_UpdateCommand "
OnCancelCommand="ddlMonthlyRecurring_CancelCommand "
Width="500px">
<HeaderTemplate>
Monthly Recurring Bills
</HeaderTemplate>
<EditItemStyle Font-Size="12px" BackColor="LemonChiffon"></EditItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<asp:LinkButton id="button1" runat="server" Text="Edit" Width="100px"
CommandName="edit"></asp:LinkButton>
<asp:Label id=lblBillName runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>' Width="150px">
</asp:Label>
<asp:Label id=lblBillValue runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>' Width="150px">
</asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="16px" BackColor="#AAAADD"></HeaderStyle>
<EditItemTemplate>
<asp:Label id="Textbox1" runat="server" Text='Bill Name:'></asp:Label>
<asp:TextBox id="Label_BillName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:Label id="Label_BillValue" runat="server" Text='Bill
Value:'></asp:Label>
<asp:TextBox id=Text1 runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:LinkButton id="button2" runat="server" Text="Update"
CommandName="update" Width="30px"></asp:LinkButton>
<asp:LinkButton id="button3" runat="server" Text="Cancel"
CommandName="cancel" Width="30px"></asp:LinkButton>
</EditItemTemplate>
</asp:datalist>
Thanks
Bharat

"Karl" wrote:
I think I need more information...where's the update button located? Is it on the same control as the datagrid? it it a button inside the datagrid
(like the edit button).

Perhaps additional code would be useful to me..

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
> Hi karl,
> Yeah I was rebinding the datalist in each roundtrip. But the problem is if
> I don't rebind, the datalist control doesnot show up. So how do I do this. >
> Any Help??
>
> Thanks
> Bharat
>
>
> "Karl" wrote:
>
> > not 100%...are you rebinding the datalist each time? You should only bind
> > it the first time I think...
> >
> > Karl
> >
> > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > news:60**********************************@microsof t.com...
> > > Karl,
> > > I thought I figured it out but now I am facing a different kind of
> > > problem. When I click on edit of the datalist the controls defined in the
> > > edit control show up as they should be. I change some values and then > > click
> > > update. Update event is never raised.
> > >
> > > What can casue this problem. I am loading the datalist into a
placeholder
> > > each each round trip to the server since I load this datalist
dynamically.
> > >
> > > What could be the problem.
> > >
> > > Thanks
> > > Bharat
> > >
> > >
> > >
> > > "Karl" wrote:
> > >
> > > > Bharat,
> > > > If I understand correctly, you are in a tricky situation....but its > > > > something worth clearly understanding and learning.
> > > >
> > > > Basically what's happening (or rather what isn't happening) is that you
> > need
> > > > to _reload_ the controls when the edit button is clicked. What you have
> > is
> > > > this:
> > > >
> > > > Link Button 1 click -->
> > > > Control 1 loaded -->
> > > > Edit Clicked -->
> > > > NOTHING
> > > >
> > > > What you need is this:
> > > >
> > > > Link button 1 clicked -->
> > > > Control 1 loaded -->
> > > > Edit Clicked -->
> > > > Control 1 Loaded -->
> > > > Woohoooo
> > > >
> > > > One of the easiest ways to achieve this is to keep the name of the > > control
> > > > in viewstate object. This will let you know which control to reload > > when
> > > > the edit button is clicked:
> > > >
> > > > Link button 1 clicked -->
> > > > Control 1 loaded -->
> > > > Control name/path stored in viewstate -->
> > > > Edit Clicked -->
> > > > Control name/path retrieved from viewstate -->
> > > > Control 1 Loaded -->
> > > > Woohoooo
> > > >
> > > > Hope that helps.
> > > >
> > > > Karl
> > > >
> > > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > > news:4E**********************************@microsof t.com...
> > > > > Hi Folks,
> > > > > Suppose I have two link button on a page (say lnkBtn1 and
> > > > > lnkBtn2). On the click event of the lnkbtn1 I have to add a
> > dynamically
> > > > > created control. And On the click event of the lnkBtn2 I have to add a
> > > > > datalist control.
> > > > > Using this datalist control I should be able to add
edit,
> > modify
> > > > > and cancel the items listed in this control.
> > > > >
> > > > > Here is how I designed. I used placeholder to add the controls
> > dynamically
> > > > > to the page on the click events of the buttons. Everything seems to be
> > > > > working fine until I click on the edit button of the datalist
control.
> > > > This
> > > > > control disappears and the corresponding event handler is not
raised.
> > > > >
> > > > > Can anyone help how to change my design to suit my needs.
> > > > >
> > > > > Thanks
> > > > > Bharat
> > > >
> > > >
> > > >
> >
> >
> >


Nov 18 '05 #9
I'm not sure I can help... When enableviewstate=true, if you click button 1
then button 2, it'll append one control after another, is that what you are
saying the problem is? It won't do that if you set enableviewstate="false",
but then you lose your events.

I can think of 3 solutions..not sure if they'll actually work though

[a] - in the click events of your buttons call placeholder.controls.Clear()
Page_Load will get called, in the viewstate it will see "control1.ascx" so
it'll load it
the Button2 event will fire, it will clear the control1.ascx and load
control2.ascx
You are still going to have the performance of loading 2, but only 1 will
get displayed

[b] - Look at Request.Form["__EVENTTARGET"] in the page_load and in
conjuction with what's in the viewstate you might be able to figure out (and
get away with) loading the right control (dunno about this)

[c] - instead of using linkbuttons and postback, use normal <a tags with a
querystring. This will let you know which "event" to load in the
page_load - which is really your problem.
Page_Loads, sees no querystring, doesn't do anything
ATag 1 clicked, Page_Loads sees ?Blah=1 and loads the first user
control1.ascx
editbutton clicked in control1.ascx, querystring will still be ?Blah=1
(asp.net maintains querystring on postback), Page_Load will reaload
control1.ascx and events should tie
ATag 2 clicked, page_loads sees ?blah=2, control1.ascx is NEVER loaded,
control2.ascx is loaded

Hope one of those works.

Karl
"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi Karl,
Thankyou very much. I got it to work your way, yet there is one more problem. Since I am using a placeholder to load the user controls on click
events of the link buttons. I had the enableviewstate property set to false for the placeholder because I had to load different controls on click events of those link buttons.
If I set the enableviewstate property to true then the place holder can load the same type of controls that were loaded in the previous
roundtrip. For this reason I cannot load new controls into placeholder. If I set to false I have to bind the datalist in the roundtrips to the server.
Then all the events trigerred on the datalist are lost.

How can I get around this and be able to load the only needed controls? Any suggestions would be appretiated.

Thanks
Bharat
"Karl" wrote:
Here's how I got it working, this is the codebehind for my usercontrol:

private void Page_Load(object sender, EventArgs e) {
if(!((WebForm1)Page).IsControlReloaded){
BindGrid();
}
}
private void BindGrid() {
DataTable dt = new DataTable();
dt.Columns.Add("BillName");
dt.Columns.Add("BillValue");
for (int i = 0; i < 5; i++){
DataRow dr = dt.NewRow();
dr[0] = 1*(i + 1);
dr[1] = 3*(i + 1);
dt.Rows.Add(dr);
}
grdUpload.DataSource = dt;
grdUpload.DataBind();
}
protected void ddlMonthlyRecurring_EditCommand(object sender,
DataListCommandEventArgs e) {
grdUpload.EditItemIndex = e.Item.ItemIndex;
BindGrid();

}
protected void ddlMonthlyRecurring_UpdateCommand(object sender,
DataListCommandEventArgs e) {
TextBox Label_BillName =
(TextBox)e.Item.FindControl("Label_BillName");
//do whatever
}

Now, the only tricky part is the code in the Page_Load. As you can see, it used the isControlReloaded of the Page to see if this is an internal
postback (you can't simply use Page.IsPostBack because then it won't work the first time around). This is what the WebForm1 page codebehind looks
like:

public bool IsControlReloaded = false;
protected LinkButton lnk;
protected PlaceHolder plc;
private void Page_Load(object sender, EventArgs e) {
string c = (string)ViewState["c"];
if (c != null){
isControlReloaded = true;
plc.Controls.Add(Page.LoadControl(c));
}
}
private void lnk_Click(object sender, EventArgs e) {
ViewState.Add("c", "u1.ascx");
plc.Controls.Add(Page.LoadControl("u1.ascx"));
}
I hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
Yeah update button is in the datalist like the edit button. Here is the control description. When I place this directly on the form the update

event
is raised. Only when I load this datalist control into a placeholder all problems rise. If I don't rebind on every trip to server the control all together dissapears.
<asp:datalist id="ddlMonthlyRecurring" runat="server" Font-Size="12pt"
BorderColor="black" BorderWidth="2"
GridLines="Both" CellPadding="5" CellSpacing="0" Font-Name="Verdana"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="aqua"

OnEditCommand="ddlMonthlyRecurring_EditCommand"
OnUpdateCommand="ddlMonthlyRecurring_UpdateCommand "
OnCancelCommand="ddlMonthlyRecurring_CancelCommand "
Width="500px">
<HeaderTemplate>
Monthly Recurring Bills
</HeaderTemplate>
<EditItemStyle Font-Size="12px" BackColor="LemonChiffon"></EditItemStyle> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<asp:LinkButton id="button1" runat="server" Text="Edit" Width="100px"
CommandName="edit"></asp:LinkButton>
<asp:Label id=lblBillName runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>' Width="150px">
</asp:Label>
<asp:Label id=lblBillValue runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>' Width="150px">
</asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="16px" BackColor="#AAAADD"></HeaderStyle>
<EditItemTemplate>
<asp:Label id="Textbox1" runat="server" Text='Bill Name:'></asp:Label>
<asp:TextBox id="Label_BillName" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillName") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:Label id="Label_BillValue" runat="server" Text='Bill
Value:'></asp:Label>
<asp:TextBox id=Text1 runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "BillValue") %>'>
</asp:TextBox>
<BR>
<BR>
<asp:LinkButton id="button2" runat="server" Text="Update"
CommandName="update" Width="30px"></asp:LinkButton>
<asp:LinkButton id="button3" runat="server" Text="Cancel"
CommandName="cancel" Width="30px"></asp:LinkButton>
</EditItemTemplate>
</asp:datalist>
Thanks
Bharat

"Karl" wrote:

> I think I need more information...where's the update button located? Is
it
> on the same control as the datagrid? it it a button inside the
datagrid > (like the edit button).
>
> Perhaps additional code would be useful to me..
>
> Karl
>
> "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> news:F2**********************************@microsof t.com...
> > Hi karl,
> > Yeah I was rebinding the datalist in each roundtrip. But the problem is
> if
> > I don't rebind, the datalist control doesnot show up. So how do I
do this.
> >
> > Any Help??
> >
> > Thanks
> > Bharat
> >
> >
> > "Karl" wrote:
> >
> > > not 100%...are you rebinding the datalist each time? You should

only
> bind
> > > it the first time I think...
> > >
> > > Karl
> > >
> > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > news:60**********************************@microsof t.com...
> > > > Karl,
> > > > I thought I figured it out but now I am facing a
different kind
> of
> > > > problem. When I click on edit of the datalist the controls
defined in
> the
> > > > edit control show up as they should be. I change some values
and then
> > > click
> > > > update. Update event is never raised.
> > > >
> > > > What can casue this problem. I am loading the datalist into a
> placeholder
> > > > each each round trip to the server since I load this datalist
> dynamically.
> > > >
> > > > What could be the problem.
> > > >
> > > > Thanks
> > > > Bharat
> > > >
> > > >
> > > >
> > > > "Karl" wrote:
> > > >
> > > > > Bharat,
> > > > > If I understand correctly, you are in a tricky
situation....but its
> > > > > something worth clearly understanding and learning.
> > > > >
> > > > > Basically what's happening (or rather what isn't happening)
is that
> you
> > > need
> > > > > to _reload_ the controls when the edit button is clicked.
What you
> have
> > > is
> > > > > this:
> > > > >
> > > > > Link Button 1 click -->
> > > > > Control 1 loaded -->
> > > > > Edit Clicked -->
> > > > > NOTHING
> > > > >
> > > > > What you need is this:
> > > > >
> > > > > Link button 1 clicked -->
> > > > > Control 1 loaded -->
> > > > > Edit Clicked -->
> > > > > Control 1 Loaded -->
> > > > > Woohoooo
> > > > >
> > > > > One of the easiest ways to achieve this is to keep the name
of the
> > > control
> > > > > in viewstate object. This will let you know which control
to reload
> > > when
> > > > > the edit button is clicked:
> > > > >
> > > > > Link button 1 clicked -->
> > > > > Control 1 loaded -->
> > > > > Control name/path stored in viewstate -->
> > > > > Edit Clicked -->
> > > > > Control name/path retrieved from viewstate -->
> > > > > Control 1 Loaded -->
> > > > > Woohoooo
> > > > >
> > > > > Hope that helps.
> > > > >
> > > > > Karl
> > > > >
> > > > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > > > news:4E**********************************@microsof t.com...
> > > > > > Hi Folks,
> > > > > > Suppose I have two link button on a page (say

lnkBtn1
> and
> > > > > > lnkBtn2). On the click event of the lnkbtn1 I have to add
a > > > dynamically
> > > > > > created control. And On the click event of the lnkBtn2 I have to
> add a
> > > > > > datalist control.
> > > > > > Using this datalist control I should be able to

add > edit,
> > > modify
> > > > > > and cancel the items listed in this control.
> > > > > >
> > > > > > Here is how I designed. I used placeholder to add the controls > > > dynamically
> > > > > > to the page on the click events of the buttons. Everything

seems
> to be
> > > > > > working fine until I click on the edit button of the datalist > control.
> > > > > This
> > > > > > control disappears and the corresponding event handler is not > raised.
> > > > > >
> > > > > > Can anyone help how to change my design to suit my needs.
> > > > > >
> > > > > > Thanks
> > > > > > Bharat
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>


Nov 18 '05 #10
Hi,

I tried the first two methods that you have listed. None seems to be
working. What I did is just added a new placeholder for each linkbutton on
the page. However my page has at present only three main linkbuttons. In the
click event of one linkbutton I clear out the contents of the other
placeholder and load the one corresponding to the current one. I got a way
around this still keeping the enableviewstate = true.

I still wonder what is the best way to solve this problem though I got it to
work.

Thanks for all the help.
Your suggestion were very useful.

Thanks
Bharat
"Karl" wrote:
I'm not sure I can help... When enableviewstate=true, if you click button 1
then button 2, it'll append one control after another, is that what you are
saying the problem is? It won't do that if you set enableviewstate="false",
but then you lose your events.

I can think of 3 solutions..not sure if they'll actually work though

[a] - in the click events of your buttons call placeholder.controls.Clear()
Page_Load will get called, in the viewstate it will see "control1.ascx" so
it'll load it
the Button2 event will fire, it will clear the control1.ascx and load
control2.ascx
You are still going to have the performance of loading 2, but only 1 will
get displayed

[b] - Look at Request.Form["__EVENTTARGET"] in the page_load and in
conjuction with what's in the viewstate you might be able to figure out (and
get away with) loading the right control (dunno about this)

[c] - instead of using linkbuttons and postback, use normal <a tags with a
querystring. This will let you know which "event" to load in the
page_load - which is really your problem.
Page_Loads, sees no querystring, doesn't do anything
ATag 1 clicked, Page_Loads sees ?Blah=1 and loads the first user
control1.ascx
editbutton clicked in control1.ascx, querystring will still be ?Blah=1
(asp.net maintains querystring on postback), Page_Load will reaload
control1.ascx and events should tie
ATag 2 clicked, page_loads sees ?blah=2, control1.ascx is NEVER loaded,
control2.ascx is loaded

Hope one of those works.

Karl
"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi Karl,
Thankyou very much. I got it to work your way, yet there is one

more
problem. Since I am using a placeholder to load the user controls on click
events of the link buttons. I had the enableviewstate property set to

false
for the placeholder because I had to load different controls on click

events
of those link buttons.
If I set the enableviewstate property to true then the place

holder
can load the same type of controls that were loaded in the previous
roundtrip. For this reason I cannot load new controls into placeholder. If

I
set to false I have to bind the datalist in the roundtrips to the server.
Then all the events trigerred on the datalist are lost.

How can I get around this and be able to load the only needed controls?

Any
suggestions would be appretiated.

Thanks
Bharat
"Karl" wrote:
Here's how I got it working, this is the codebehind for my usercontrol:

private void Page_Load(object sender, EventArgs e) {
if(!((WebForm1)Page).IsControlReloaded){
BindGrid();
}
}
private void BindGrid() {
DataTable dt = new DataTable();
dt.Columns.Add("BillName");
dt.Columns.Add("BillValue");
for (int i = 0; i < 5; i++){
DataRow dr = dt.NewRow();
dr[0] = 1*(i + 1);
dr[1] = 3*(i + 1);
dt.Rows.Add(dr);
}
grdUpload.DataSource = dt;
grdUpload.DataBind();
}
protected void ddlMonthlyRecurring_EditCommand(object sender,
DataListCommandEventArgs e) {
grdUpload.EditItemIndex = e.Item.ItemIndex;
BindGrid();

}
protected void ddlMonthlyRecurring_UpdateCommand(object sender,
DataListCommandEventArgs e) {
TextBox Label_BillName =
(TextBox)e.Item.FindControl("Label_BillName");
//do whatever
}

Now, the only tricky part is the code in the Page_Load. As you can see, it used the isControlReloaded of the Page to see if this is an internal
postback (you can't simply use Page.IsPostBack because then it won't work the first time around). This is what the WebForm1 page codebehind looks
like:

public bool IsControlReloaded = false;
protected LinkButton lnk;
protected PlaceHolder plc;
private void Page_Load(object sender, EventArgs e) {
string c = (string)ViewState["c"];
if (c != null){
isControlReloaded = true;
plc.Controls.Add(Page.LoadControl(c));
}
}
private void lnk_Click(object sender, EventArgs e) {
ViewState.Add("c", "u1.ascx");
plc.Controls.Add(Page.LoadControl("u1.ascx"));
}
I hope that helps.

Karl

"Bharat" <Bh****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
> Yeah update button is in the datalist like the edit button. Here is the > control description. When I place this directly on the form the update
event
> is raised. Only when I load this datalist control into a placeholder all > problems rise. If I don't rebind on every trip to server the control all > together dissapears.
>
>
> <asp:datalist id="ddlMonthlyRecurring" runat="server" Font-Size="12pt"
> BorderColor="black" BorderWidth="2"
> GridLines="Both" CellPadding="5" CellSpacing="0" Font-Name="Verdana"
> HeaderStyle-BackColor="#aaaadd"
> AlternatingItemStyle-BackColor="Gainsboro"
> EditItemStyle-BackColor="aqua"
OnEditCommand="ddlMonthlyRecurring_EditCommand"
> OnUpdateCommand="ddlMonthlyRecurring_UpdateCommand "
> OnCancelCommand="ddlMonthlyRecurring_CancelCommand "
> Width="500px">
> <HeaderTemplate>
> Monthly Recurring Bills
> </HeaderTemplate>
> <EditItemStyle Font-Size="12px" BackColor="LemonChiffon"></EditItemStyle> > <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
> <ItemTemplate>
> <asp:LinkButton id="button1" runat="server" Text="Edit" Width="100px"
> CommandName="edit"></asp:LinkButton>
> <asp:Label id=lblBillName runat="server" Text='<%#
> DataBinder.Eval(Container.DataItem, "BillName") %>' Width="150px">
> </asp:Label>
> <asp:Label id=lblBillValue runat="server" Text='<%#
> DataBinder.Eval(Container.DataItem, "BillValue") %>' Width="150px">
> </asp:Label>
> </ItemTemplate>
> <HeaderStyle Font-Size="16px" BackColor="#AAAADD"></HeaderStyle>
> <EditItemTemplate>
> <asp:Label id="Textbox1" runat="server" Text='Bill Name:'></asp:Label>
> <asp:TextBox id="Label_BillName" runat="server" Text='<%#
> DataBinder.Eval(Container.DataItem, "BillName") %>'>
> </asp:TextBox>
> <BR>
> <BR>
> <asp:Label id="Label_BillValue" runat="server" Text='Bill
> Value:'></asp:Label>
> <asp:TextBox id=Text1 runat="server" Text='<%#
> DataBinder.Eval(Container.DataItem, "BillValue") %>'>
> </asp:TextBox>
> <BR>
> <BR>
> <asp:LinkButton id="button2" runat="server" Text="Update"
> CommandName="update" Width="30px"></asp:LinkButton>
> <asp:LinkButton id="button3" runat="server" Text="Cancel"
> CommandName="cancel" Width="30px"></asp:LinkButton>
> </EditItemTemplate>
> </asp:datalist>
>
>
> Thanks
> Bharat
>
> "Karl" wrote:
>
> > I think I need more information...where's the update button located? Is it
> > on the same control as the datagrid? it it a button inside the datagrid > > (like the edit button).
> >
> > Perhaps additional code would be useful to me..
> >
> > Karl
> >
> > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > news:F2**********************************@microsof t.com...
> > > Hi karl,
> > > Yeah I was rebinding the datalist in each roundtrip. But the problem is
> > if
> > > I don't rebind, the datalist control doesnot show up. So how do I do this.
> > >
> > > Any Help??
> > >
> > > Thanks
> > > Bharat
> > >
> > >
> > > "Karl" wrote:
> > >
> > > > not 100%...are you rebinding the datalist each time? You should
only
> > bind
> > > > it the first time I think...
> > > >
> > > > Karl
> > > >
> > > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > > news:60**********************************@microsof t.com...
> > > > > Karl,
> > > > > I thought I figured it out but now I am facing a different kind
> > of
> > > > > problem. When I click on edit of the datalist the controls defined in
> > the
> > > > > edit control show up as they should be. I change some values and then
> > > > click
> > > > > update. Update event is never raised.
> > > > >
> > > > > What can casue this problem. I am loading the datalist into a
> > placeholder
> > > > > each each round trip to the server since I load this datalist
> > dynamically.
> > > > >
> > > > > What could be the problem.
> > > > >
> > > > > Thanks
> > > > > Bharat
> > > > >
> > > > >
> > > > >
> > > > > "Karl" wrote:
> > > > >
> > > > > > Bharat,
> > > > > > If I understand correctly, you are in a tricky situation....but its
> > > > > > something worth clearly understanding and learning.
> > > > > >
> > > > > > Basically what's happening (or rather what isn't happening) is that
> > you
> > > > need
> > > > > > to _reload_ the controls when the edit button is clicked. What you
> > have
> > > > is
> > > > > > this:
> > > > > >
> > > > > > Link Button 1 click -->
> > > > > > Control 1 loaded -->
> > > > > > Edit Clicked -->
> > > > > > NOTHING
> > > > > >
> > > > > > What you need is this:
> > > > > >
> > > > > > Link button 1 clicked -->
> > > > > > Control 1 loaded -->
> > > > > > Edit Clicked -->
> > > > > > Control 1 Loaded -->
> > > > > > Woohoooo
> > > > > >
> > > > > > One of the easiest ways to achieve this is to keep the name of the
> > > > control
> > > > > > in viewstate object. This will let you know which control to reload
> > > > when
> > > > > > the edit button is clicked:
> > > > > >
> > > > > > Link button 1 clicked -->
> > > > > > Control 1 loaded -->
> > > > > > Control name/path stored in viewstate -->
> > > > > > Edit Clicked -->
> > > > > > Control name/path retrieved from viewstate -->
> > > > > > Control 1 Loaded -->
> > > > > > Woohoooo
> > > > > >
> > > > > > Hope that helps.
> > > > > >
> > > > > > Karl
> > > > > >
> > > > > > "Bharat" <Bh****@discussions.microsoft.com> wrote in message
> > > > > > news:4E**********************************@microsof t.com...
> > > > > > > Hi Folks,
> > > > > > > Suppose I have two link button on a page (say
lnkBtn1
> > and
> > > > > > > lnkBtn2). On the click event of the lnkbtn1 I have to add a > > > > dynamically
> > > > > > > created control. And On the click event of the lnkBtn2 I have to
> > add a
> > > > > > > datalist control.
> > > > > > > Using this datalist control I should be able to add > > edit,
> > > > modify
> > > > > > > and cancel the items listed in this control.
> > > > > > >
> > > > > > > Here is how I designed. I used placeholder to add the controls > > > > dynamically
> > > > > > > to the page on the click events of the buttons. Everything
seems
> > to be
> > > > > > > working fine until I click on the edit button of the datalist > > control.
> > > > > > This
> > > > > > > control disappears and the corresponding event handler is not > > raised.
> > > > > > >
> > > > > > > Can anyone help how to change my design to suit my needs.
> > > > > > >
> > > > > > > Thanks
> > > > > > > Bharat
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> >
> >
> >


Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fabrizio | last post by:
Hi, I'm trying to create a page with a datalist that loads from a template the ItemTemplate, which contains a linkbutton that should have the commandname = "edit" But when I click on the link...
3
by: Hardy Wang | last post by:
Hi all; I have a DataList with ItemCreated event like below: private void myList_ItemCreated(object sender , DataListItemEventArgs e) { DataRowView myRowView; DataRow myRow; if (e.Item.DataItem...
1
by: mahsa | last post by:
H data I'm binding to the DataList is information about products in my product database. Perhaps passed in the QueryString to this page is a ProductID. I might want to make the item in the DataList...
2
by: News | last post by:
Hi, I need help with datalist and linkbutton. I need a LinkButton to display in datalist if datafield "is_measure_customchecklist" in a db table set to true. Here is the code (in parts): ...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
4
by: News | last post by:
Hi, I need help with datalist and linkbutton. I need a LinkButton to be visible in datalist only on the condition when datafield "is_measure_customchecklist" in a db table set to true. Here...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
3
by: mayankaswal | last post by:
I am using a DataList and I have used a PlaceHolder to generate the Headers and Items. The problem is when the items list is big and I scroll down, the header also moves. I am trying the header to be...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.