By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Help Needed -- Datalist linkbutton

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.