aspx_beginners thread: Setting DataGrid column values from code, not in <asp> tag?
Most <asp: controls have an id you can set, which you can then use in your
code to set all the other properties.
i.e. <textarea id="thisText" runat="server" />
thisText.Value = "Hello there";
thisText.Rows = 20;
thisText.Cols = 40;
etc...
is there a way to set the properties of the HyperLinkColumn and/or
BoundColumn for a DataGrid from the code?
the datagrid below works, but i would like to beable to set the
HyperLinkColumn properties like this
list.HyperLinkColumn.DataNavigateUrlField = "ID";
list.HyperLinkColumn.DataNavigateUrlFormatString = "form.aspx?
action=Edit&ID={0}";
list.HyperLinkColumn.DataTextField = "Title";
then the diplay would be completly removed from the logic
<asp:HyperLinkColumn /> of course this is where an id property would come
in handy.
instead of like this -
<asp:DataGrid
id="list"
AutoGenerateColumns="false"
ShowHeader="false"
runat="server">
<Columns>
<asp:BoundColumn DataField="ID" Visible="false" />
<asp:BoundColumn DataField="Title" Visible="false" />
<asp:TemplateColumn>
<itemtemplate>
<b> - </b>
</itemtemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn
DataNavigateUrlField="ID"
DataNavigateUrlFormatString="form.aspx?action=Edit&ID={0}"
DataTextField="Title" />
</Columns>
</asp:DataGrid>
on another note is it possible to insert comments in a datagrid
this seems to throw an erorr
<asp:DataGrid id="list" runat="server" />
<Columns>
<!-- Hidden Data --->
<asp:BoundColumn DataField="ID" Visible="false" />
<asp:BoundColumn DataField="Title" Visible="false" />
<!-- for formatting only -->
<asp:TemplateColumn>
<itemtemplate>
<b> - </b>
</itemtemplate>
</asp:TemplateColumn>
<!-- Link to Edit Form -->
<asp:HyperLinkColumn
DataNavigateUrlField="ID"
DataNavigateUrlFormatString="form.aspx?action=Edit&ID={0}"
DataTextField="Title" />
</asp:DataGrid>