473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 gvEntitiesRowDa taBound(object sender, GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", " + ""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);
gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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 6196
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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:D5******** *************** ***********@mic rosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", " +
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);
gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:D5******** *************** ***********@mic rosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", " +
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);
gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:D5******** *************** ***********@mic rosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", " +
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);
gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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="trSubheadin gs">
<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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B5******** *************** ***********@mic rosoft.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.mic rosoft.comwrote in
message
news:D5******* *************** ************@mi crosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", "
+
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);

gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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="trSubheadin gs">
<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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B5******** *************** ***********@mic rosoft.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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in
message
news:D5******** *************** ***********@mic rosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", "
+
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);

gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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><%#DataBinde r.Eval(Containe r.DataItem, "q2option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q3option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q4option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q5option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q6option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q7option") %></td>
<td><%#DataBind er.Eval(Contain er.DataItem, "q8option") %></td>
<td><%#DataBind er.Eval(Contain er.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="trSubheadin gs">
<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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B5******** *************** ***********@mic rosoft.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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in
message
news:D5******** *************** ***********@mic rosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
td.BackColor = System.Drawing. Color.Bisque;

LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", "
+
""
+ ") - ";
td.Controls.Add (lbl);

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

LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);

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

gvr.Cells.Add(t d);

gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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

"WebBuilder 451" 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="trSubheadin gs">
<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
"WebBuilder 451" <We***********@ discussions.mic rosoft.comwrote in message
news:B5******** *************** ***********@mic rosoft.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.mic rosoft.comwrote in
>message
>news:D5******* *************** ************@mi crosoft.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 gvEntitiesRowDa taBound(object sender,
GridViewRowEven tArgs
e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
EntityReport er = (EntityReport)e .Row.DataItem;
if (er.SzName != ctrlName)
{
GridViewRow gvr = new GridViewRow(0, 0,
DataControlRowT ype.Header, DataControlRowS tate.Insert);
TableCell td = new TableCell();
td.ColumnSpan = 9;
td.Font.Bold = true;
td.Font.Size = FontUnit.Smalle r;
td.HorizontalAl ign = HorizontalAlign .Center;
>
>
td.BackColor = System.Drawing. Color.Bisque;
>
LinkButton lbtn = new LinkButton();
lbtn.ID = "EditEntity ";
lbtn.CommandArg ument = er.IEntityID.To String();
lbtn.CommandNam e = "Edit Entity";
lbtn.Command += EditEntityComma nd;
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.EntityTypeDe sc + ", "
+
""
+ ") - ";
td.Controls.Add (lbl);
>
Literal ltr1 = new Literal();
ltr1.Text = " ";
td.Controls.Add (ltr1);
>
>
>
LinkButton lbtn2 = new LinkButton();
lbtn2.ID = "NewEntity" ;
lbtn2.CommandAr gument = er.IEntityID.To String();
lbtn2.CommandNa me = "newEntity" ;
lbtn2.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn3.CommandNa me = "newEntity" ;
lbtn3.Command += EditEntityComma nd;
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.CommandAr gument = er.IEntityID.To String();
lbtn4.CommandNa me = "newEntity" ;
lbtn4.Command += EditEntityComma nd;
lbtn4.Text = "Add new phone for contact";
td.Controls.Add (lbtn4);
>
Literal ltr4 = new Literal();
ltr4.Text = " ";
td.Controls.Add (ltr4);
>
gvr.Cells.Add(t d);
>
gvEntities.Cont rols[0].Controls.AddAt (e.Row.DataItem Index +
icur, gvr);
ctrlName = er.SzName;
icur+=1;
}
}
}
// this is the function that is to be fired
protected void EditEntityComma nd(object sender, CommandEventArg s 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
4879
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 the best method? Do you have a sample of how to do this?
0
1873
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 collect the data in the Textboxes which i added dynamically from server side, i am not able to do . Alos i tried to bedug, the total no of rows in Html table does not reflect the dynamically added rows.
0
2399
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 version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
0
1321
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: OnButtonClick: I call a method that adds the new boundfield
0
1965
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: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; position: absolute; top: 132px" Width="688px" BackColor="White" BorderColor="#CCCCCC"...
2
3121
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 the user only sees certain columns based on the XML file. In my ASCX page I simply defined the gridview <asp:GridView ID="gvSearchResults" HorizontalAlign="Center" AllowSorting="true" runat="server"
2
3288
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 like what is shown in the following PNG image. http://farm3.static.flickr.com/2183/1805431357_1facb1ed9b_o.png I know how to dynamically add rows to the end of the table, but how do
1
1711
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 page "Next" and "Previous" which I want displayed just a couple of lines below the table dynamically. Thus the positions of these buttons would vary depending on how many rows are rendered. I was wondering whether there is a programmatic way of...
0
1671
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 the GridView header where I type the number of rows I want to show in insert mode. Say I type 12. 2. When I click Add, the GridView changes to insert mode showing the 12 rows ready to be filled in. I would use a custom template for insert mode. 3....
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.