adding rows dynamically to a gridview problem

W

WebBuilder451

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
 
E

Eliyahu Goldin

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 said:
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
 
W

WebBuilder451

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 said:
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 said:
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
 
W

WebBuilder451

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 said:
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 said:
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
 
E

Eliyahu Goldin

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 said:
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 said:
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


message
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
 
W

WebBuilder451

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 said:
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 said:
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 said:
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


message
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
 
N

Neha

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 said:
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 said:
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 said:
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


message
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
 
N

Neha

And one more thing ,

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

Please help

WebBuilder451 said:
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 said:
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 said:
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


:

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


message
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top