Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Modify Datagrid HeaderTemplate through code

Reply
Thread Tools

Modify Datagrid HeaderTemplate through code

 
 
Dave A.
Guest
Posts: n/a
 
      08-14-2005
I have an editable datagrid with HeaderTemplates that have to be written
through code, with data from the database. I can only find code to add new
columns and modify text. Is there any way to be able to modify existing
HeaderTemplate.Text values?


thanks
Dave A.
 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      08-15-2005
You can do it once the row is created. I do this in a sample here (it's using
the 2.0 GridView, but the concept is same for v1.1 DataGrid):

http://staff.develop.com/ballen/blog...2-8095a848d821

-Brock
DevelopMentor
http://staff.develop.com/ballen



> I have an editable datagrid with HeaderTemplates that have to be
> written through code, with data from the database. I can only find
> code to add new columns and modify text. Is there any way to be able
> to modify existing HeaderTemplate.Text values?
>
> thanks
> Dave A.




 
Reply With Quote
 
 
 
 
Dave A.
Guest
Posts: n/a
 
      08-15-2005
How is this function called - _grid_RowDataBound(), and will I need to loop
through the HeaderTemplate row to modify the text? Instead of looping through
the whole row, can I refer to the column index?

Dave A.

"Brock Allen" wrote:

> You can do it once the row is created. I do this in a sample here (it's using
> the 2.0 GridView, but the concept is same for v1.1 DataGrid):
>
> http://staff.develop.com/ballen/blog...2-8095a848d821
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > I have an editable datagrid with HeaderTemplates that have to be
> > written through code, with data from the database. I can only find
> > code to add new columns and modify text. Is there any way to be able
> > to modify existing HeaderTemplate.Text values?
> >
> > thanks
> > Dave A.

>
>
>
>

 
Reply With Quote
 
Dave A.
Guest
Posts: n/a
 
      08-16-2005
Thanks for the tip. I modified your code for the datagrid. This is what worked.

<aspataGrid id="DGProducts"
runat="server"
Cellpadding="4" Cellspacing="0" Width="800"
BorderStyle="solid" BorderColor="black" BorderWidth="1"
AlternatingItemStyle-BackColor="palegoldenrod"
ItemStyle BackColor="beige"
HeaderStyle-CssClass="productsHead"
Font-Size="10"
AutoGenerateColumns="false"
OnEditCommand="DGProducts_Edit"
OnCancelCommand="DGProducts_Cancel"
OnUpdateCommand="DGProducts_Update"
OnItemDataBound="Item_Bound">


Public Sub Item_Bound(sender As Object, e As DataGridItemEventArgs)

Dim itemType As ListItemType
Dim intCell As TableCell

itemType = CType(e.Item.ItemType, ListItemType)

If (itemType = ListItemType.Header) Then
intCell = CType(e.Item.Controls(4), TableCell)
intCell.Text = "fy text"
End If
End Sub

thanks,
Dave A.
"Brock Allen" wrote:

> You can do it once the row is created. I do this in a sample here (it's using
> the 2.0 GridView, but the concept is same for v1.1 DataGrid):
>
> http://staff.develop.com/ballen/blog...2-8095a848d821
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > I have an editable datagrid with HeaderTemplates that have to be
> > written through code, with data from the database. I can only find
> > code to add new columns and modify text. Is there any way to be able
> > to modify existing HeaderTemplate.Text values?
> >
> > thanks
> > Dave A.

>
>
>
>

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      08-16-2005
The DataGrid (again in 1.1, which is a bit different than my 2.0 sample)
has a ItemDataBound event. This will get called after each row (including
the the header) is full created and populated with data.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> How is this function called - _grid_RowDataBound(), and will I need to
> loop through the HeaderTemplate row to modify the text? Instead of
> looping through the whole row, can I refer to the column index?
>
> Dave A.
>
> "Brock Allen" wrote:
>
>> You can do it once the row is created. I do this in a sample here
>> (it's using the 2.0 GridView, but the concept is same for v1.1
>> DataGrid):
>>
>> http://staff.develop.com/ballen/blog...d=c35c43f6-568
>> 6-40ee-9752-8095a848d821
>>
>> -Brock
>> DevelopMentor
>> http://staff.develop.com/ballen
>>> I have an editable datagrid with HeaderTemplates that have to be
>>> written through code, with data from the database. I can only find
>>> code to add new columns and modify text. Is there any way to be able
>>> to modify existing HeaderTemplate.Text values?
>>>
>>> thanks
>>> Dave A.




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find control in headertemplate of datagrid Cheng ASP .Net 2 11-14-2007 03:57 PM
controlling button in headertemplate datagrid JoNa SuperGold ASP .Net 1 04-05-2005 10:02 PM
DataGrid HeaderTemplate Question Ashish Sharma ASP .Net 0 04-14-2004 08:07 PM
Can we bind data to textbox in a headertemplate of a datagrid Vijaya ASP .Net 2 11-13-2003 06:42 AM
How do you access controls in the HeaderTemplate of a DataGrid SamIAm ASP .Net 1 06-26-2003 09:04 AM



Advertisments