1
GridView

<asp:GridView ID="gview1" runat="server" AutoGenerateColumns="False" 
GridLines="Horizontal" AutoGenerateRows="false" 
onrowcommand="gview1_RowCommand"onDataKeyNames="lId,lName"BackColor="White" 
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
  CssClass="gridview1" >
  <AlternatingRowStyle BackColor="#DCDCDC" />
   <Columns>
    <asp:TemplateField HeaderText="Search Results">
     <ItemTemplate>
       <asp:HiddenField ID="hdnFieldLid"runat="server"Value='<%#Eval("lId")%>'  />
                    <asp:LinkButton ID="link" runat="server" Text='<%# Eval("lName") %>'
                     CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'
                     CommandName="select" ></asp:LinkButton>
                     </ItemTemplate>
            </asp:TemplateField>
        </Columns>

GridView の背後にあるコード

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        get_search();
    }
       }

public void get_search()
{
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "lichen_Namesearch";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = con;
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@lName", Session["lName"].ToString());
    cmd.Parameters.AddWithValue("@uName", Session["uName"].ToString());
    cmd.Parameters.AddWithValue("@cName", Session["cName"].ToString());
    cmd.Parameters.AddWithValue("@sName", Session["sName"].ToString());
    DataTable dt = new DataTable();
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    adp.Fill(dt);
    gview1.DataSource = dt;
    gview1.DataBind();
}



protected void gview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "select")
    {
        int index = Convert.ToInt32(e.CommandArgument.ToString());
        LinkButton lnkBtn = (LinkButton)gview1.Rows[index].FindControl("link");
        HiddenField hdnFieldlid = (HiddenField)gview1.Rows[index].FindControl("hdnFieldLid");
        Session["lName"] = lnkBtn.Text.Trim();
        Response.Redirect("../RealDatabase/Default2.aspx");
    }
}

Default2 は、DetailsView が構成されている次のページです。

      <asp:DetailsView ID="DetailsView1" runat="server" Width="1402px" 
        CssClass="detailsview" AutoGenerateRows="False" CellPadding="10" 
        ForeColor="Black" GridLines="None" BackColor="LightGoldenrodYellow" 
        BorderColor="#660033" BorderWidth="4px">
        <AlternatingRowStyle BackColor="PaleGoldenrod" />
        <EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"/>
    <Fields>
      <asp:BoundField
       DataField="lId" 
       HeaderText="Id" 
       InsertVisible="False" 
       ReadOnly="True" 
       SortExpression="lId" HeaderStyle-Font-Bold="true" />
   <asp:BoundField 
     DataField="lName" 
     HeaderText="Name" 
     SortExpression="lName"
     HeaderStyle-Font-Bold="true" />
   <asp:TemplateField HeaderText="Image" HeaderStyle-Font-Bold="true">
      <ItemTemplate>
         <asp:Image ID="Image1" runat="server" ImageUrl='<%# "pics"+"/"+Eval("picPath") %>'
       Width="500px" Height="300px" />
                </ItemTemplate>
                </asp:TemplateField>
   <asp:BoundField 
     DataField="citationName" 
     HeaderText="Citation" 
     SortExpression="citationName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="synonymName" 
     HeaderText="Synonym" 
     SortExpression="synonymName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="basionym" 
     HeaderText="Basionym" 
     ReadOnly="True" 
     SortExpression="basionym"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="kingName" 
     HeaderText="Kingdom" 
     SortExpression="kingName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="phlyllumName" 
     HeaderText="Phyllum" 
     SortExpression="phlyllumName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="className" 
     HeaderText="Class" 
     SortExpression="className"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="orderName" 
     HeaderText="Order" 
     SortExpression="orderName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="familyName" 
     HeaderText="Family" 
     SortExpression="familyName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="genusName" 
     HeaderText="Genus" 
     SortExpression="genusName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="description" 
     HeaderText="Description" 
     SortExpression="description"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="chemName" 
     HeaderText="Chemistry" 
     SortExpression="chemName"
     HeaderStyle-Font-Bold="true" />
<asp:BoundField 
     DataField="countryName" 
     HeaderText="World Distribution" 
     SortExpression="countryName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="statesName" 
     HeaderText="Indian Distribution" 
     SortExpression="statesName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="habitName" 
     HeaderText="Habit" 
     SortExpression="habitName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="habitatName" 
     HeaderText="Found In Habitat" 
     SortExpression="habitatName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="altitudeRange" 
     HeaderText="Altitude Range" 
     SortExpression="altitudeRange"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="usesName" 
     HeaderText="Uses" 
     SortExpression="usesName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="usesDescription" 
     HeaderText="Uses Description" 
     SortExpression="usesDescription"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="otherInfo" 
     HeaderText="Other Information" 
     SortExpression="otherInfo"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="linksName" 
     HeaderText="Links" 
     SortExpression="linksName"
     HeaderStyle-Font-Bold="true" />
     <asp:BoundField 
     DataField="referencesName" 
     HeaderText="References" 
     SortExpression="referencesName"
     HeaderStyle-Font-Bold="true" />
      </Fields>
        <FooterStyle BackColor="Tan" />
        <HeaderStyle BackColor="Tan" Font-Bold="True" />
        <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
            HorizontalAlign="Center" />
     </asp:DetailsView>

DetailsView のコード ビハインド

    protected void Page_Load(object sender, EventArgs e)
    {
       get_searchDetails();  //search function
      }
      public void get_searchDetails()
    {
         SqlCommand cmd = new SqlCommand();
         cmd.CommandText = "get_lichenDetails";
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Connection = con;
         cmd.Parameters.Clear();
         cmd.Parameters.AddWithValue("@sName", Session["sName"].ToString());
         cmd.Parameters.AddWithValue("@uName", Session["uName"].ToString());
         cmd.Parameters.AddWithValue("@lName", Session["lName"].ToString());
         cmd.Parameters.AddWithValue("@cName", Session["cName"].ToString());
         DataTable dt = new DataTable();
         SqlDataAdapter adp = new SqlDataAdapter(cmd);
         adp.Fill(dt);
         DetailsView1.DataSource = dt;
         DetailsView1.DataBind();
      }

検索の詳細には地衣類のリストが表示されます (リンク ボタン) これらのボタンをクリックすると、各地衣類の詳細が detailsView に表示されます。

4

0 に答える 0