【发布时间】:2014-05-13 03:41:01
【问题描述】:
我有一个gridview,它显示了一个包含TaskId、Title、Reward、Time Allotted、Poster Name 列的所有数据库表。尽管我所有的SqlConnection 代码都存在于另一个用于将数据插入到数据库表中的网络表单上。
这是我在InsertTask.aspx.cs 页面上的代码:
protected void btnPost_Click(object sender, EventArgs e)
{
string CS = ConfigurationManager.ConnectionStrings["ABCD"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spTasks", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Title", txtTitle.Text);
cmd.Parameters.AddWithValue("@Body", txtBody.Text);
cmd.Parameters.AddWithValue("@Reward", txtRewards.Text);
cmd.Parameters.AddWithValue("@TimeAllotted", txtTime.Text);
cmd.Parameters.AddWithValue("@PosterName", txtPoster.Text);
con.Open();
cmd.ExecuteNonQuery();
lblStatus.Text = "Task Posted Successfully.";
}
}
这会将任务成功插入到数据库表中。所以在default.aspx 的新网络表单上,我有一个gridview,它连接到该数据库表并显示表中的任务列表。
同样,我没有在default.aspx.cs上写任何代码。
我需要做的是将Title 作为gridview 中的超链接,我可以单击它并根据行进入不同的页面。可以这样做吗?或者我应该在所有行上使用一个按钮来相应地访问其他页面。怎么可能?
我没有使用gridview 的经验。
【问题讨论】:
-
您可以在模板字段中使用链接按钮或使用 CommandField 并设置 ButtonType="Link"。