Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
or
g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
/>
<meta name="keywords" content="Datagrid,header,text, Datagrid header text" />
<meta name="description" content="Hi, I'm wondering how can i change the datagri
d header text at runtime so that it keeps the sorting enabled? I can do; e.Item.
Cells[0].Text = "foo"; But then foo is" />
</tr>
</table>
<!-- / controls above postbits -->
<!-- toolbar -->
<div class="tcat">
<div class="tcat_right">
<table cellpadding="0" cellspacing="0" style="float:right;">
<tr>
<td class="vbmenu_c" id="threadtools" nowrap="nowrap">
<a rel="nofollow" href="http://www.velocityreviews.com/forums/t8
0435-datagrid-header-text.html?nojs=1#goto_threadtools" accesskey="3">Thread Too
ls</a>
<script type="text/javascript"> vbmenu_register("threadtools");
</script>
</td>
</tr>
</table>
<div class="tcat_left">
<h1>
Datagrid header text
</h1>
</div>
</div>
</div>
<!-- / toolbar -->
<div class="thead" style="height:10px;margin-bottom:2px;">
</div>
<!-- / controls --> </td>
<td id="td_post_381694" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->
06-14-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381694" class="KonaBody">
<!-- google_ad_section_start -->
Hi, I'm wondering how can i change the datagrid header text at runtime s
o<br />
that it keeps the sorting enabled?<br />
<br />
I can do;<br />
<br />
e.Item.Cells[0].Text = "foo";<br />
<br />
But then foo is the text of the table cell and not the underlying hyperlink<br /
>
and as such, foo is no longer sortable.<br />
<br />
I've tried things like...<br />
<br />
((HyperLink)(e.Item.Cells[0].Controls[0]).Text = "foo";<br />
<br />
But I get a null exception. In fact for some unknown reason,<br />
e.Item.Cells[0].Controls.Count == 0!!!!<br />
<br />
Can someone please show me what it is that I'm doing wrong here?<br />
<br />
Thanks,<br />
Ben<br />
<br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->
</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop"> </div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">
</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">
<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&p=381694" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>
<script type="text/javascript">
<!--
var customadstyle = 'postbit';
google_ad_client = 'pub-9482258749662266';
google_ad_channel ="2683886312";
google_ad_output = 'js';
google_max_num_ads = '3';
google_ad_type = 'text,image,flash,html';
google_image_size = '336x280';
google_feedback = 'on';
google_skip = google_adnum;
// -->
</script>
</div>
<div> </div>
<!-- / controls --> </td>
<td id="td_post_381729" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->
06-14-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381729" class="KonaBody">
<!-- google_ad_section_start -->
Ben,<br />
<br />
I think you'll have to use "FindControl" and then cast the control fou
nd to<br />
the hyperlink.<br />
<br />
--<br />
Sincerely,<br />
<br />
S. Justin Gengo, MCP<br />
Web Developer / Programmer<br />
<br />
<a rel="nofollow" href="http://www.aboutfortunate.com" target="_blank">www.about
fortunate.com</a><br />
<br />
"Out of chaos comes order."<br />
Nietzsche<br />
"Ben" <> wrote in message<br />
news:01hzc.750$...<font color="blue"><br />
> Hi, I'm wondering how can i change the datagrid header text at runtime so<b
r />
> that it keeps the sorting enabled?<br />
><br />
> I can do;<br />
><br />
> e.Item.Cells[0].Text = "foo";<br />
><br />
> But then foo is the text of the table cell and not the underlying</font><br
/>
hyperlink<font color="blue"><br />
> and as such, foo is no longer sortable.<br />
><br />
> I've tried things like...<br />
><br />
> ((HyperLink)(e.Item.Cells[0].Controls[0]).Text = "foo";<br />
><br />
> But I get a null exception. In fact for some unknown reason,<br />
> e.Item.Cells[0].Controls.Count == 0!!!!<br />
><br />
> Can someone please show me what it is that I'm doing wrong here?<br />
><br />
> Thanks,<br />
> Ben<br />
><br />
><br />
></font><br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->
</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop"> </div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">
</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">
<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&p=381729" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>
<!-- post 381729 popup menu -->
<div class="vbmenu_popup" id="postmenu_381729_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">S. Justin Gengo</td>
</tr>
</table>
</div>
<!-- / post 381729 popup menu -->
</div>
<!-- / controls --> </td>
<td id="td_post_381891" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->
06-15-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381891" class="KonaBody">
<!-- google_ad_section_start -->
Hi Ben,<br />
<br />
From your description, you're wondering how to change the DataGrid(has set<br />
columns's sort property) 's header text at runtime and also keep the<br />
datagrid sortable ,yes?<br />
<br />
Based on my research, the Header in the DataGrid in the Asp.net DataGrid<br />
control is represented by a DataGridLinkButton control(is a internal<br />
control hidden from developer) rather than a normal HyperLink or LinkButton<br /
>
control. So we can retrieve it as generally we do. However, I think we can<br />
change the Header's Text by setting the certain DataGrid Column's<br />
HeaderText property since the HeaderText is set for each Column, isn't it?<br />
For example:<br />
<br />
dgMain.Columns[1].HeaderText = "fdsaf";<br />
<br />
Thus, we can get the proper columns via DataGrid.Columns collection in a<br />
certain postback event and then change its HeaderText , but be care that we<br /
>
have to rebind the DataGrid with datasource after we change the HeaderText<br />
of a column , for example:<br />
<br />
private void btnChangeSortText_Click(object sender, System.EventArgs e)<br />
{<br />
dgMain.Columns[1].HeaderText = "fdsaf";<br />
Bind_Data();<br />
}<br />
<br />
Hope helps. Thanks.<br />
<br />
<br />
Regards,<br />
<br />
Steven Cheng<br />
Microsoft Online Support<br />
<br />
Get Secure! <a rel="nofollow" href="http://www.microsoft.com/security" target="_
blank">www.microsoft.com/security</a><br />
(This posting is provided "AS IS", with no warranties, and confers no<
br />
rights.)<br />
<br />
Get Preview at ASP.NET whidbey<br />
<a rel="nofollow" href="http://msdn.microsoft.com/asp.net/whidbey/default.aspx"
target="_blank">http://msdn.microsoft.com/asp.net/whidbey/default.aspx</a><br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->
</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop"> </div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">
</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">
<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&p=381891" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>
</table>
</div>
<!-- / post 381891 popup menu -->
</div>
<div> </div>
<!-- / controls --> </td>
<td id="td_post_381988" class="pbmiddle">
<div class="pbmiddletop"></div>
<div class="pbmessage">
<table cellpadding="0" cellspacing="0" width="100%" align="center" style="margin
-bottom:3px;">
<tr>
<td align="right">
<!-- status icon and date -->
06-15-2004
<!-- / status icon and date -->
</td>
</tr>
</table>
<!-- message -->
<div id="post_message_381988" class="KonaBody">
<!-- google_ad_section_start -->
After doing some research it looks like a good place to do this is in th
e<br />
ItemCreated event of the datagrid. The one catch is that the itemcreated<br />
fires in the viewstate init function. Which I thought was odd.<br />
<br />
Nevertheless, here is what I ended up doing...<br />
<br />
<br />
private void dgSubordinate_ItemCreated(object sender,<br />
System.Web.UI.WebControls.DataGridItemEventArgs e)<br />
{<br />
if (e.Item.ItemType != ListItemType.Header) return;<br />
<br />
string HeaderText = null;<br />
<br />
if (oSecurity != null)<br />
{<br />
switch (oSecurity.ReportType)<br />
{<br />
case SecurityPermissions.Regional:<br />
HeaderText = "SVP";<br />
break;<br />
case SecurityPermissions.SVP:<br />
HeaderText = "VP";<br />
break;<br />
case SecurityPermissions.VP:<br />
HeaderText = "AE";<br />
break;<br />
}<br />
((LinkButton)e.Item.Cells[0].Controls[0]).Text = HeaderText;<br />
}<br />
}<br />
<br />
<br />
So, that's working just fine. I ended up needing the oSecurity != null<br />
check becuase of the fact that the ItemCreate is fired in the<br />
viewstateinit(or whatever its called). Since my security object doesn't<br />
exist until Page_Load, I needed the null check. At some point I'll look<br />
into the initilization of the datagrid and see why it's creating items so<br />
early, but I can guess. Anyway, thanks for your help.<br />
<br />
<br />
"Steven Cheng[MSFT]" <v-> wrote in message<br />
news:...<font color="blue"><br />
> Hi Ben,<br />
><br />
> From your description, you're wondering how to change the DataGrid(has set<
br />
> columns's sort property) 's header text at runtime and also keep the<br />
> datagrid sortable ,yes?<br />
><br />
> Based on my research, the Header in the DataGrid in the Asp.net DataGrid<b
r />
> control is represented by a DataGridLinkButton control(is a internal<br />
> control hidden from developer) rather than a normal HyperLink or</font><br
/>
LinkButton<font color="blue"><br />
> control. So we can retrieve it as generally we do. However, I think we can<
br />
> change the Header's Text by setting the certain DataGrid Column's<br />
> HeaderText property since the HeaderText is set for each Column, isn't it?<
br />
> For example:<br />
><br />
> dgMain.Columns[1].HeaderText = "fdsaf";<br />
><br />
> Thus, we can get the proper columns via DataGrid.Columns collection in a<br
/>
> certain postback event and then change its HeaderText , but be care that</f
ont><br />
we<font color="blue"><br />
> have to rebind the DataGrid with datasource after we change the HeaderText<
br />
> of a column , for example:<br />
><br />
> private void btnChangeSortText_Click(object sender, System.EventArgs e)<br
/>
> {<br />
> dgMain.Columns[1].HeaderText = "fdsaf";<br />
> Bind_Data();<br />
> }<br />
><br />
> Hope helps. Thanks.<br />
><br />
><br />
> Regards,<br />
><br />
> Steven Cheng<br />
> Microsoft Online Support<br />
><br />
> Get Secure! <a rel="nofollow" href="http://www.microsoft.com/security" targ
et="_blank">www.microsoft.com/security</a><br />
> (This posting is provided "AS IS", with no warranties, and confer
s no<br />
> rights.)<br />
><br />
> Get Preview at ASP.NET whidbey<br />
> <a rel="nofollow" href="http://msdn.microsoft.com/asp.net/whidbey/default.a
spx" target="_blank">http://msdn.microsoft.com/asp.net/whidbey/default.aspx</a><
br />
></font><br />
<br />
<br />
<br />
<!-- google_ad_section_end -->
</div>
<!-- / message -->
</div> </td>
<td class="pbright" rowspan="3" width="14" align="center">
<div class="pbrighttop"> </div></td>
</tr>
<tr>
<td height="100%" valign="bottom" class="pbmiddle" style="padding-right:5px;">
<div class="pbmessage">
</div>
</td>
</tr>
<tr>
<td class="pbmiddle" align="right" style="padding-right:5px;">
<a href="http://www.velocityreviews.com/forums/newreply.
php?do=newreply&p=381988" rel="nofollow"><img src="/forums/images/buttons/qu
ote.gif" alt="Reply With Quote" border="0" /></a>
</td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td>
</tr>
</table>
</table>
</div>
<!-- / post 381988 popup menu -->
</td>
<td class="pbright" rowspan="2" width="14" align="center">
<div class="pbrighttop"> </div></td></tr>
<tr>
<td style="padding-right: 5px" class="pbmiddle" align="right"> </td>
</tr>
<tr>
<td class="pbleftbot"></td>
<td class="pbmiddlebot"></td>
<td class="pbrightbot"></td></tr></tbody></table></div>
</div>
</tr>
</table>
<!-- / controls below postbits -->
<!-- lightbox scripts -->
<script type="text/javascript" src="clientscript/vbulletin_lightbox.js?v
=386"></script>
<script type="text/javascript">
<!--
vBulletin.register_control("vB_Lightbox_Container", "posts", 1);
//-->
</script>
<!-- / lightbox scripts -->
</table>
</form>
</div>
<!-- / thread tools menu -->
<!-- **************************************************** -->
<br />
<img src="http://www.velocityreviews.com/forums/cron.php?rand=1304399700
" alt="" width="1" height="1" border="0" />
</div>
</div>
</div>
<!-- / close content container -->
<!-- /content area table -->
<script type="text/javascript">
<!--
// Main vBulletin Javascript Initialization
vBulletin_init();
//-->
</script>
<div class="topadvert">
<script type="text/javascript"><!--
e9 = new Object();
e9.size = "728x90,468x60";
e9.noAd = 1;
//--></script>
<script type="text/javascript" src="http://tags.expo9.exponential.com/tags/Veloc
ityReviewscom/ROS/tags.js"></script>
</div>
<script type="text/javascript">
var vglnk = { api_url: '//api.viglink.com/api',
key: 'a1b43bb7c89550212cc6e8e52d78e22a' };
(function(d, t) {
var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;
s.src = ('https:' == document.location.protocol ? vglnk.api_url :
'//cdn.viglink.com/api') + '/vglnk.js';
var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r);
}(document, 'script'));
</script>
<br /><div style="z-index:3" class="smallfont" align="center"><a href="http://ww
w.velocityreviews.com/forums/archive/f-3.html">1</a> <a href="http://www.velocit
yreviews.com/forums/archive/f-10.html">2</a> <a href="http://www.velocityreviews
.com/forums/archive/f-11.html">3</a> <a href="http://www.velocityreviews.com/for
ums/archive/f-14.html">4</a> <a href="http://www.velocityreviews.com/forums/arch
ive/f-9.html">5</a> <a href="http://www.velocityreviews.com/forums/archive/f-1.h
tml">6</a> <a href="http://www.velocityreviews.com/forums/archive/f-44.html">7</
a> <a href="http://www.velocityreviews.com/forums/archive/f-5.html">8</a> <a hre
f="http://www.velocityreviews.com/forums/archive/f-6.html">9</a> <a href="http:/
/www.velocityreviews.com/forums/archive/f-13.html">10</a> <a href="http://www.ve
locityreviews.com/forums/archive/f-7.html">11</a> <a href="http://www.velocityre
views.com/forums/archive/f-22.html">12</a> <a href="http://www.velocityreviews.c
om/forums/archive/f-23.html">13</a> <a href="http://www.velocityreviews.com/foru
ms/archive/f-16.html">14</a> <a href="http://www.velocityreviews.com/forums/arch
ive/f-57.html">15</a> <a href="http://www.velocityreviews.com/forums/archive/f-3
3.html">16</a> <a href="http://www.velocityreviews.com/forums/archive/f-41.html"
>17</a> <a href="http://www.velocityreviews.com/forums/archive/f-38.html">18</a>
<a href="http://www.velocityreviews.com/forums/archive/f-46.html">19</a> <a hre
f="http://www.velocityreviews.com/forums/archive/f-19.html">20</a> <a href="http
://www.velocityreviews.com/forums/archive/f-34.html">21</a> <a href="http://www.
velocityreviews.com/forums/archive/f-35.html">22</a> <a href="http://www.velocit
yreviews.com/forums/archive/f-37.html">23</a> <a href="http://www.velocityreview
s.com/forums/archive/f-40.html">24</a> <a href="http://www.velocityreviews.com/f
orums/archive/f-20.html">25</a> <a href="http://www.velocityreviews.com/forums/a
rchive/f-27.html">26</a> <a href="http://www.velocityreviews.com/forums/archive/
f-47.html">27</a> <a href="http://www.velocityreviews.com/forums/archive/f-56.ht
ml">28</a> <a href="http://www.velocityreviews.com/forums/archive/f-24.html">29<
/a> <a href="http://www.velocityreviews.com/forums/archive/f-25.html">30</a> <a
href="http://www.velocityreviews.com/forums/archive/f-26.html">31</a> <a href="h
ttp://www.velocityreviews.com/forums/archive/f-48.html">32</a> <a href="http://w
ww.velocityreviews.com/forums/archive/f-49.html">33</a> <a href="http://www.velo
cityreviews.com/forums/archive/f-50.html">34</a> <a href="http://www.velocityrev
iews.com/forums/archive/f-52.html">35</a> <a href="http://www.velocityreviews.co
m/forums/archive/f-53.html">36</a> <a href="http://www.velocityreviews.com/forum
s/archive/f-51.html">37</a> <a href="http://www.velocityreviews.com/forums/archi
ve/f-55.html">38</a> <a href="http://www.velocityreviews.com/forums/archive/f-42
.html">39</a> <a href="http://www.velocityreviews.com/forums/archive/f-43.html">
40</a> <a href="http://www.velocityreviews.com/forums/archive/f-39.html">41</a>
<a href="http://www.velocityreviews.com/forums/archive/f-29.html">42</a> <a href
="http://www.velocityreviews.com/forums/archive/f-30.html">43</a> <a href="http:
//www.velocityreviews.com/forums/archive/f-31.html">44</a> <a href="http://www.v
elocityreviews.com/forums/archive/f-32.html">45</a> <a href="http://www.velocity
reviews.com/forums/archive/f-18.html">46</a> <a href="http://www.velocityreviews
.com/forums/archive/f-17.html">47</a> </div>
<script type="text/javascript">
//<![CDATA[
window.orig_onload = window.onload;
window.onload = function() {
var cpost=document.location.hash.substring(1);var cpost2='';if(cpost){ var ispos
t=cpost.substring(0,4)=='post';if(ispost)cpost2='post_'+cpost.substring(4);if((c
obj = fetch_object(cpost))||(cobj = fetch_object(cpost2))){cobj.scrollIntoView(t
rue);}else if(ispost){cpostno = cpost.substring(4,cpost.length);if(parseInt(cpos
tno)>0){location.replace('http://www.velocityreviews.com/forums/showthread.php?p
='+cpostno);};} }
if(typeof window.orig_onload == "function") window.orig_onload();
}
//]]>
</script>
</body>
</html>