0

我在 asp.net 中的数据网格视图仅将 sql server 数据库中的选定 ID 显示为单行。

现在我需要在单击特定 id(数据行)时显示特定页面,并且我想在属于所选 id 的新页面中显示所有详细信息(单击 id)。

我试过这段代码:

protected void btnserch_Click(object sender, EventArgs e)
{
    SqlConnection objsqlconnection = new SqlConnection(CONNECTIONSTRING);
    string query = "Select id from registration";
    SqlCommand objsqlcommand = new SqlCommand(query, objsqlconnection);
    objsqlconnection.Open();
    SqlDataAdapter da=new SqlDataAdapter();
    DataSet ds=new DataSet();
    objsqlcommand.CommandText = query; 
    objsqlcommand.Connection = objsqlconnection;  
    da = new SqlDataAdapter(objsqlcommand);  
    da.Fill(ds);  
    objsqlcommand.ExecuteNonQuery();  
    GridView1.DataSource = ds; 
    GridView1.DataBind();
    objsqlconnection.Close();
}

此代码通过从注册表中仅选择 id 列来返回一个网格。现在,当我单击 id 列的数据行时,我需要另一个页面来显示属于该 id 的所有详细信息。

4

3 回答 3

0

就像@MelanciaUK 说的“OnItemDataBound”是你的朋友。要在回发时检查 ID,请在“SelectedIndexChanging”中选择它

希望能帮助到你。

于 2013-08-14T01:43:30.987 回答
0

重定向到新页面的最简单方法:

<asp:GridView ID="grd" runat="server" autogeneratedcolumn="false">
<asp:TemplateField HaderText="ID">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HaderText="Name">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HaderText="Edit">
<ItemTemplate>
<a href='Newpage.aspx?ID=<%#Eval("ID")%>'>Edit</a> 
<ItemTemplate>
<asp:TemplateField>
<asp:GridView>
于 2013-09-26T06:54:10.220 回答
0

您可以通过两种方式从一个页面重定向到另一个页面

<asp:GridView ID="grd" runat="server" autogeneratedcolumn="false"> 
   <asp:TemplateField HaderText="Action">
   <ItemTemplate>
     <a href='mypage.aspx?ID=<%#Eval("RowID")%>'>Edit</a> 
     <a href='javascript:void(0);' onclick="Redirect(<%#Eval("RowID")%>);">Edit</a> 

   <ItemTemplate>
   <asp:TemplateField>
<asp:GridView> 


<script type="text/javascript">

function Redirect(id) {
    window.location = 'mypage.aspx?ID=' + id;
}
</script>
于 2013-09-26T07:03:14.753 回答