1

私のデータグリッドはSQL-Serverデータベースにバインドされています。データグリッドには、各部屋の情報が表示されます。asp.netの最後に、詳細を示す列を追加しました。ユーザーが目的の部屋の横にある詳細をクリックすると、その部屋の新しいWebページが開きます。ただし、問題が発生する可能性があります。ユーザーが検索を行う部屋を探すときに、各詳細リンクが特定の部屋にリンクされるようにするにはどうすればよいですか。

リンクを保持するために、そのSqlデータベースルームテーブル内に実際に新しい列を追加する必要があると今考えていますか?これは可能ですか誰もがこれに対する解決策を持っています。

4

2 に答える 2

2

グリッドビューにハイパーリンクフィールドを追加するだけです

DataNavigateUrlFormatStringプロパティで、テンプレートアドレスを詳細ページに書き込みます(例: "Details.aspx?id = {0}")。DataNavigateUrlFieldsで、行のIDを含むDB列の名前を書き込みます。IDフィールドの内容は、DataNavigateUrlFormatStringの{0}部分を自動的に置き換えます。

MSDNの例:

<columns>

  <asp:boundfield datafield="OrderID" 
    headertext="OrderID"/>
  <asp:boundfield datafield="CustomerID" 
    headertext="Customer ID"/>
  <asp:boundfield datafield="OrderDate" 
    headertext="Order Date"
    dataformatstring="{0:d}" />
  <asp:hyperlinkfield text="Details..."
    navigateurl="~\details.aspx"            
    headertext="Order Details"
    target="_blank" />

</columns>

于 2012-09-03T09:48:54.217 に答える
1

aspxページ:

<asp:Label ID="lblRoomName" runat="server"></asp:Label>

背後にあるコード:

string strRoomId = Request.QueryString["Id"].ToString();
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconstr"].ConnectionString);
SqlCommand sqlcommand = new SqlCommand("Select * from RoomDetails where RoomId = @RoomId", sqlCon);
sqlcommand.Parameters.AddWithValue("@RoomId", strRoomId);
SqlDataAdapter da = new SqlDataAdapter(sqlcommand);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
于 2012-09-03T11:51:12.947 に答える