Missing header text and values for templatecolumn

G

Guest

Hi,

I use a datagrid with asp:templatecolumn, and handles the datagrid's
ItemDataBound event, whereby I assign a value to this asp:templatecolumn text.

e.Item.Cells[1].Text = e.Item.Cells[2].Text + e.Item.Cells[3].Text;
/* column index 2 and 3 are boundcolumn */

The issue that I have is that the column header (index 1) would be blank
after it.

Furthermore, after postback, the values for the individual rows (only column
index 1) will be missing as well. Is this because on postback, as I didn't
rebind the datagrid, so the event didn't run, thus the system erase the data
from that particular column?

Anyhow that I can fix these two issues?

Thanks.
 
M

Masudur

Hi,

I use a datagrid with asp:templatecolumn, and handles the datagrid's
ItemDataBound event, whereby I assign a value to this asp:templatecolumn text.

e.Item.Cells[1].Text = e.Item.Cells[2].Text + e.Item.Cells[3].Text;
/* column index 2 and 3 are boundcolumn */

The issue that I have is that the column header (index 1) would be blank
after it.

Furthermore, after postback, the values for the individual rows (only column
index 1) will be missing as well. Is this because on postback, as I didn't
rebind the datagrid, so the event didn't run, thus the system erase the data
from that particular column?

Anyhow that I can fix these two issues?

Thanks.

Hi.. a little bit strange problem ... because what ever you do if you
don't change the header text it is suppose to persists after post
back...
did you changed you databoundcode after chacking the rowtype...
protected void gdvData_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// your code goes here...
}
}

one more thing ... check your gridviews EnableViewState property set
to true or not....
can could you please show some sample code of your templatecolumn....

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Guest

Hi Masudur,

thanks. but i can't find e.Row.RowType as i use ItemDataBound instead of
RowDataBound. Should I enable the viewstate for it to work?


eg.
<asp:templatecolumn headertext="Name">
<itemstyle horizontalalign="left" width="15%"></itemstyle>
<itemtemplate>
<asp:label id="lblDisplayedName" runat="server" />
</itemtemplate> </asp:templatecolumn>


Masudur said:
Hi,

I use a datagrid with asp:templatecolumn, and handles the datagrid's
ItemDataBound event, whereby I assign a value to this asp:templatecolumn text.

e.Item.Cells[1].Text = e.Item.Cells[2].Text + e.Item.Cells[3].Text;
/* column index 2 and 3 are boundcolumn */

The issue that I have is that the column header (index 1) would be blank
after it.

Furthermore, after postback, the values for the individual rows (only column
index 1) will be missing as well. Is this because on postback, as I didn't
rebind the datagrid, so the event didn't run, thus the system erase the data
from that particular column?

Anyhow that I can fix these two issues?

Thanks.

Hi.. a little bit strange problem ... because what ever you do if you
don't change the header text it is suppose to persists after post
back...
did you changed you databoundcode after chacking the rowtype...
protected void gdvData_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// your code goes here...
}
}

one more thing ... check your gridviews EnableViewState property set
to true or not....
can could you please show some sample code of your templatecolumn....

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
M

Masudur

Hi,

Sorry missed out the point that you are using datagrid...
is it asp.net 1.1 or 2.0?
try this...
protected void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
//your code goes here
}
}
and viewstate of datagrid should be enabled...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top