473,230 Members | 1,330 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,230 software developers and data experts.

adding rows dynamically to a gridview problem

I'm adding subheadings to a gridview. Each sub head has a few link buttons.
I'm adding the controls in the rowdatabound event code follows: sorry about
the length here. I have to be missing something. The buttons show up and post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", " + ""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);
gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
....
....
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
Sep 9 '08 #1
7 6153
You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using one
item template for the whole row, like in a repeater, as opposed to per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", " +
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);
gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes

Sep 10 '08 #2
thanks, I'll need to learn how and doing that now.

appreciated
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using one
item template for the whole row, like in a repeater, as opposed to per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", " +
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);
gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Sep 10 '08 #3
amended..
can you share an example or point to an aritcal that covers what you suggest?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using one
item template for the whole row, like in a repeater, as opposed to per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", " +
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);
gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Sep 10 '08 #4
Here is an example for a repeater. It will help you to get the idea:

<asp:repeater>
<headertemplate>
<table>
</headertemplate>
<itemtemplate>
<tr runat="server" id="trNormal">
<td>Databind expression for column 1</td>
<td>Databind expression for column 2</td>
<td>Databind expression for column 3</td>
</tr>
<tr runat="server" id="trSubheadings">
<td>Databind expression for subheading 1</td>
<td>Databind expression for subheading 2</td>
<td>Databind expression for subheading 3</td>
</tr>
</itemtemplate>
</asp:repeater>
<footertemplate>
</table>
</footertemplate>

Handle ItemDataBound event to hide trNormal or trSubheadings as needed.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
amended..
can you share an example or point to an aritcal that covers what you
suggest?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
>You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using
one
item template for the whole row, like in a repeater, as opposed to
per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in
message
news:D5**********************************@microso ft.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up
and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", "
+
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);

gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes



Sep 10 '08 #5
ok, thanks
This was a bit more straight forward than i expected. I thought you ment to
create a custom template type for the subhead. perhaps using template builder.
thanks very much appreciated.


--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
Here is an example for a repeater. It will help you to get the idea:

<asp:repeater>
<headertemplate>
<table>
</headertemplate>
<itemtemplate>
<tr runat="server" id="trNormal">
<td>Databind expression for column 1</td>
<td>Databind expression for column 2</td>
<td>Databind expression for column 3</td>
</tr>
<tr runat="server" id="trSubheadings">
<td>Databind expression for subheading 1</td>
<td>Databind expression for subheading 2</td>
<td>Databind expression for subheading 3</td>
</tr>
</itemtemplate>
</asp:repeater>
<footertemplate>
</table>
</footertemplate>

Handle ItemDataBound event to hide trNormal or trSubheadings as needed.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
amended..
can you share an example or point to an aritcal that covers what you
suggest?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using
one
item template for the whole row, like in a repeater, as opposed to
per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in
message
news:D5**********************************@microsof t.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up
and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", "
+
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);

gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


Sep 10 '08 #6
Hi ,

As i am new in asp.net c# ,can you please make it more specififc.

I am using a repeater control and i bound the columns like this

td><%#DataBinder.Eval(Container.DataItem, "q2option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q3option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q4option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q5option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q6option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q7option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q8option")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "q9option")%></td>
</tr>
I mean in the databind expression for subheading how can i do that.

This is veru urgent.Please help me.

I am running out of time.

Thanks in advance.
"Eliyahu Goldin" wrote:
Here is an example for a repeater. It will help you to get the idea:

<asp:repeater>
<headertemplate>
<table>
</headertemplate>
<itemtemplate>
<tr runat="server" id="trNormal">
<td>Databind expression for column 1</td>
<td>Databind expression for column 2</td>
<td>Databind expression for column 3</td>
</tr>
<tr runat="server" id="trSubheadings">
<td>Databind expression for subheading 1</td>
<td>Databind expression for subheading 2</td>
<td>Databind expression for subheading 3</td>
</tr>
</itemtemplate>
</asp:repeater>
<footertemplate>
</table>
</footertemplate>

Handle ItemDataBound event to hide trNormal or trSubheadings as needed.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
amended..
can you share an example or point to an aritcal that covers what you
suggest?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
You don't need to add controls dynamically. Instead, use templated fields
made out of 2 rows, one for regular items and another for those with
subheadings. In the RowDataBound event decide if you need to show
subheadings.

If you can, it is better to use a ListView control since it allows using
one
item template for the whole row, like in a repeater, as opposed to
per-field
templates in GridView.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in
message
news:D5**********************************@microsof t.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up
and
post
back, but the events do not fire.
any help would be appreciated!!!

Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
td.BackColor = System.Drawing.Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);

Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);

Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", "
+
""
+ ") - ";
td.Controls.Add(lbl);

Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);

Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);

LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);

LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);

Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);

gvr.Cells.Add(td);

gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


Oct 16 '08 #7
And one more thing ,

Based on the search result i have to show the header for each category of
products.

Please help

"WebBuilder451" wrote:
ok, thanks
This was a bit more straight forward than i expected. I thought you ment to
create a custom template type for the subhead. perhaps using template builder.
thanks very much appreciated.


--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
"Eliyahu Goldin" wrote:
Here is an example for a repeater. It will help you to get the idea:

<asp:repeater>
<headertemplate>
<table>
</headertemplate>
<itemtemplate>
<tr runat="server" id="trNormal">
<td>Databind expression for column 1</td>
<td>Databind expression for column 2</td>
<td>Databind expression for column 3</td>
</tr>
<tr runat="server" id="trSubheadings">
<td>Databind expression for subheading 1</td>
<td>Databind expression for subheading 2</td>
<td>Databind expression for subheading 3</td>
</tr>
</itemtemplate>
</asp:repeater>
<footertemplate>
</table>
</footertemplate>

Handle ItemDataBound event to hide trNormal or trSubheadings as needed.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"WebBuilder451" <We***********@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
amended..
can you share an example or point to an aritcal that covers what you
suggest?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
>
kes
>
>
"Eliyahu Goldin" wrote:
>
>You don't need to add controls dynamically. Instead, use templated fields
>made out of 2 rows, one for regular items and another for those with
>subheadings. In the RowDataBound event decide if you need to show
>subheadings.
>>
>If you can, it is better to use a ListView control since it allows using
>one
>item template for the whole row, like in a repeater, as opposed to
>per-field
>templates in GridView.
>>
>--
>Eliyahu Goldin,
>Software Developer
>Microsoft MVP [ASP.NET]
>http://msmvps.com/blogs/egoldin
>http://usableasp.net
>>
>>
>"WebBuilder451" <We***********@discussions.microsoft.comwrote in
>message
>news:D5**********************************@microso ft.com...
I'm adding subheadings to a gridview. Each sub head has a few link
buttons.
I'm adding the controls in the rowdatabound event code follows: sorry
about
the length here. I have to be missing something. The buttons show up
and
post
back, but the events do not fire.
any help would be appreciated!!!
>
Thank you.
protected void gvEntitiesRowDataBound(object sender,
GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
EntityReport er = (EntityReport)e.Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smaller;
td.HorizontalAlign = HorizontalAlign.Center;
>
>
td.BackColor = System.Drawing.Color.Bisque;
>
LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity";
lbtn.CommandArgument = er.IEntityID.ToString();
lbtn.CommandName = "Edit Entity";
lbtn.Command += EditEntityCommand;
lbtn.Text = "(edit)";
td.Controls.Add(lbtn);
>
Literal ltr = new Literal();
ltr.Text = " ";
td.Controls.Add(ltr);
>
Label lbl = new Label();
lbl.Text = er.SzName + " (" + er.EntityTypeDesc + ", "
+
""
+ ") - ";
td.Controls.Add(lbl);
>
Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add(ltr1);
>
>
>
LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity";
lbtn2.CommandArgument = er.IEntityID.ToString();
lbtn2.CommandName = "newEntity";
lbtn2.Command += EditEntityCommand;
lbtn2.Text = "Add new person or Institution";
td.Controls.Add(lbtn2);
>
Literal ltr2 = new Literal();
ltr2.Text = "<br />";
td.Controls.Add(ltr2);
>
LinkButton lbtn3 = new LinkButton();
lbtn3.ID = "NewEmail";
lbtn3.CommandArgument = er.IEntityID.ToString();
lbtn3.CommandName = "newEntity";
lbtn3.Command += EditEntityCommand;
lbtn3.Text = "Add new email for contact";
td.Controls.Add(lbtn3);
>
>
Literal ltr3 = new Literal();
ltr3.Text = " ";
td.Controls.Add(ltr3);
>
LinkButton lbtn4 = new LinkButton();
lbtn4.ID = "NewPhone";
lbtn4.CommandArgument = er.IEntityID.ToString();
lbtn4.CommandName = "newEntity";
lbtn4.Command += EditEntityCommand;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add(lbtn4);
>
Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add(ltr4);
>
gvr.Cells.Add(td);
>
gvEntities.Controls[0].Controls.AddAt(e.Row.DataItemIndex +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityCommand(object sender, CommandEventArgs e)
{
...
...
}
i set a break point here and this does not get hit.
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)
>
kes
>>
>>
>>
Oct 16 '08 #8

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

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
0
by: ami | last post by:
Hi everyone, I have a question about dynamically adding columns to a gridview. Based on user input (after a button click), some columns are being added to my gridview. What I do: ...
0
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: ...
2
by: Kbalz | last post by:
I have a user control that has a gridview in it. I am dynamically setting up its datasource and columns based on an XML file. I have everything done except adding columns to the gridview, so that...
2
by: gnewsgroup | last post by:
I am new to the asp.net Table web control. I am using it to customize my presentation of data. I cannot implement the idea with DataGrid or GridView. Basically, I would like to have something...
1
by: Paddy | last post by:
The problem I am facing is as follows: I am populating an HTML table on my webpage with rows of data from a database. The rows may be sometimes 10 and sometimes say,3. I have two buttons on that...
0
by: Andy B | last post by:
I need to take an existing GridView that connects to a database and gets rows from a table and force it to show x rows in the insert mode. This is what should happen: 1. There is a TextBox in...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.