Displaying data - a simple question for the expert
I am already using a data grid to dispay data from the database. Which is fine, except that I wand to add Edit and Delete links in the grid table. I was thinking of going down the DataPanel route. Can you help me translate the following code such that i can still use my html <tr><td> tags to place the data I want and enter my Edit and Delete links as asp:hyperlink.
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
DataGrid1.DataSource=ListJobs();
DataGrid1.DataBind();
}
System.Data.DataSet ListJobs() {
string connectionString = "server=\'(local)\'; trusted_connection=true; database=\'nkonye_test\'";
//string connectionString = ConfigurationSettings.AppSettings("ConnectionStrin g");
System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionStri ng);
string queryString = "SELECT [Jobs].* FROM [Jobs]";
System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;
System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
dataAdapter.SelectCommand = dbCommand;
System.Data.DataSet dataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);
return dataSet;
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<table cellpadding="0" width="750" align="center" cellpsacing="0">
<tbody>
<tr>
<td align="middle" colspan="2">
List | <a href="search.aspx">Search</a> | <a href="index.aspx">Log out</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align="middle" colspan="2">
<h2>List jobs
</h2>
</td>
</tr>
<tr>
<td align="middle" colspan="2">
<a href="add_job.aspx">Add new job</a></td>
</tr>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
<asp:DataGrid id="DataGrid1" runat="server" Autogeneratecolumns="False" align="center" width="650px" ForeColor="Black" CellPadding="4" BackColor="White" BorderColor="#DEDFDE" BorderWidth="1px" GridLines="Vertical" BorderStyle="None">
<FooterStyle backcolor="#CCCC99"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#6B696B"></HeaderStyle>
<PagerStyle horizontalalign="Right" forecolor="Black" backcolor="#F7F7DE" mode="NumericPages"></PagerStyle>
<SelectedItemStyle font-bold="True" forecolor="White" backcolor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle backcolor="White"></AlternatingItemStyle>
<ItemStyle backcolor="#F7F7DE"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="job_id" HeaderText="ID" ReadOnly="True" />
<asp:BoundColumn DataField="job_title" HeaderText="Title"></asp:BoundColumn>
<asp:BoundColumn DataField="location" HeaderText="Location"></asp:BoundColumn>
<asp:BoundColumn DataField="job_type" HeaderText="Job Type"></asp:BoundColumn>
<asp:BoundColumn DataField="salary" HeaderText="Salary" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn DataField="job_type" HeaderText="Type"></asp:BoundColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
|