I need to create a DataGrid that's bound by hard coded values that I spcify in code-behind for demonstration purposes. We are gonna change it to actually bind to a data source later.
I'm not srue how to do this. I'm used to binding to a data source.
Lets say I ahve the data Grid beow. I started to create the header text from code-behind. How would I actually hard code records and then bind the grid?
<asp:datagrid id="dgTasks" runat="server"
allowsorting="true" pagesize="10" allowpaging="true" autogeneratecolumns="false
" pagerstyle-visible="false"
width="100%" allowcustompaging="false" >
<selecteditemstyle cssclass="rowdetailactive"
></selecte
ditemstyle
>
<alternatingitemstyle borderstyle="none" cssclass="AlternatingRowSt
yle_middle
"></altern
atingitems
tyle>
<itemstyle cssclass="rowdetail"></ite
mstyle>
<headerstyle cssclass="repeater_header"
></headers
tyle>
<columns>
<asp:templatecolumn sortexpression="1">
<headerstyle width="70px" wrap="false"></headerstyle
>
<itemtemplate>
<asp:image id="imgstatus" runat=server height="16px" width="16px" imageurl='<%#displayimage(
databinder
.eval(cont
ainer, "dataitem.status").tostrin
g())%>'>
</asp:image>
<%# displayclaimstatus(databin
der.eval(c
ontainer, "dataitem.RequestNumber").
tostring()
)%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="2">
<headerstyle width="100px" wrap="false"></headerstyle
>
<itemtemplate>
<asp:hyperlink id="hplPriority" runat="server"><%# databinder.eval(container,
"dataitem.Priority")%></as
p:hyperlin
k>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="3">
<headerstyle width="90px" wrap="false"></headerstyle
>
<itemtemplate>
<%# databinder.eval(container,
"dataitem.Task")%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="4">
<headerstyle width="90px" wrap="false"></headerstyle
>
<itemtemplate>
<%# displaydate(databinder.eva
l(containe
r, "dataitem.CreateDate"))%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="5">
<headerstyle width="90px" wrap="false"></headerstyle
>
<itemtemplate>
<%# displaydate(databinder.eva
l(containe
r, "dataitem.ApplicationName"
))%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="6">
<headerstyle width="140px" wrap="false"></headerstyle
>
<itemtemplate>
<%# databinder.eval(container,
"dataitem.RequestedFor")%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn sortexpression="7">
<headerstyle width="180px" wrap="false"></headerstyle
>
<itemtemplate>
<%# databinder.eval(container,
"dataitem.Status")%>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<headerstyle width="90px" wrap="false"></headerstyle
>
<itemtemplate>
<%# displaydate(databinder.eva
l(containe
r, "dataitem.Assigned"))%>
</itemtemplate>
</asp:templatecolumn>
</columns>
<pagerstyle visible="false"></pagersty
le>
</asp:datagrid>
Code-behind:
private void LoadTasks()
{
//List<string> values = new List<string>();
//values.Add("Sharepoint")
;
//values.Add("Exchange Email Account");
//values.Add("Office 2007 Enterprise");
dgTasks.Columns[0].HeaderT
ext = "Request #";
dgTasks.Columns[0].HeaderT
ext = "Priority";
dgTasks.Columns[0].HeaderT
ext = "Task";
dgTasks.Columns[0].HeaderT
ext = "Create Date";
dgTasks.Columns[0].HeaderT
ext = "Application Name";
dgTasks.Columns[0].HeaderT
ext = "Status";
dgTasks.Columns[0].HeaderT
ext = "Assigned";
dgTasks.Items.Add(new ListItem(WebUtils.GetLabel
("lblStatu
s"), "1"));
dgTasks.DataSource = values;
if (dgTasks != null)
dgTasks.DataBind();
}
Start Free Trial