iT邦幫忙

0

GridView search 結果顯示

  • 分享至 

  • xImage
    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="970px"
        BackColor="White" BorderColor="White" BorderStyle="Ridge" 
        BorderWidth="2px" CellPadding="3"
        CellSpacing="1" GridLines="None" AutoGenerateColumns="False" 
        ShowHeaderWhenEmpty="True" EnableEventValidation="false" Visible="False">
        <Columns>
            <asp:BoundField DataField="病歷號" HeaderText="病歷號" SortExpression="病歷號" />
            <asp:BoundField DataField="病患名稱" HeaderText="病患名稱" SortExpression="病患名稱" />
            <asp:BoundField DataField="建檔日期" HeaderText="建檔日期" SortExpression="建檔日期" />
            <asp:BoundField DataField="主治醫師" HeaderText="主治醫師" SortExpression="主治醫師" />
        </Columns>
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
        <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#594B9C" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#33276A" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:lseformsConnectionString %>"
        
        SelectCommand="SELECT pat_no AS 病歷號, pat_name AS 病患名稱, date AS 建檔日期, doctor AS 主治醫師 FROM cancer_plan WHERE (pat_no = @pat_no) ORDER BY 建檔日期">
        <SelectParameters>
            <asp:CookieParameter CookieName="Search_Tx" Name="pat_no" />
        </SelectParameters>
    </asp:SqlDataSource>

請教一下 以上是我gridview 的程式
我在web 上有一text欄位Search_Tx
另外有一Search按鈕 判斷 Search_Tx 是否有值
有值時 GridView1.Visible = true 另外 GridView 秀出結果
但是 目前按鈕是有GridView的隱藏顯示功能 但是 Search的結果 好像抓不到欄位值
是我用錯 <asp:CookieParameter CookieName="Search_Tx" Name="pat_no" /> <??

我解決了......但是這邊好像刪不了

修正之後的內容
前端

<asp:GridView ID="GridView1" runat="server"   
    Width="970px" BackColor="White" BorderColor="White" BorderStyle="Ridge" 
        BorderWidth="2px" CellPadding="3"
        CellSpacing="1" GridLines="None" AutoGenerateColumns="False" 
        ShowHeaderWhenEmpty="True" EnableEventValidation="false" Visible="False"
        EmptyDataText="查無資料,請用新增按鈕新增" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" > 
        <Columns>
            <asp:BoundField DataField="序號" HeaderText="序號" SortExpression="序號" />
            <asp:BoundField DataField="病歷號" HeaderText="病歷號" SortExpression="病歷號" />
            <asp:BoundField DataField="病患名稱" HeaderText="病患名稱" SortExpression="病患名稱" />
            <asp:BoundField DataField="建檔日期" HeaderText="建檔日期" SortExpression="建檔日期" />
            <asp:BoundField DataField="主治醫師" HeaderText="主治醫師" SortExpression="主治醫師" />
            <asp:HyperLinkField NavigateUrl="Cancerplan-edit.aspx" Text="修改" />
            <asp:ButtonField ButtonType="Button" CommandName="mys" Text="修改" />
        </Columns>
    </asp:GridView>

後端

protected void Serh_Bn_Click(object sender, ImageClickEventArgs e)
    {
            if (Search_Tx.Text != "")
            {
                GridView1.Visible = true;
                string ConnStr = ConfigurationManager.ConnectionStrings["lseformsConnectionString"].ConnectionString;
                SqlConnection Conn = new SqlConnection(ConnStr);
                string strSQL = "SELECT plan_no AS 序號,pat_no AS 病歷號, pat_name AS 病患名稱, date AS 建檔日期, doctor AS 主治醫師 FROM cancer_plan WHERE (pat_no = @pat_no) ORDER BY 序號";
                Conn.Open(); 
                SqlCommand comm = new SqlCommand(strSQL, Conn);
                comm.Parameters.Add(new SqlParameter("pat_no", Search_Tx.Text)); 
                DataTable dt = new DataTable(); 
                SqlDataAdapter sda = new SqlDataAdapter(comm); 
                sda.Fill(dt); 
                this.GridView1.DataSource = dt; 
                this.GridView1.DataBind();
            }
            else
            {
                Literal myMsg1 = new Literal();
                myMsg1.Text = "<script>alert('請輸入病歷號')</script><br>";
                this.Page.Controls.Add(myMsg1);
            }
    }

另外請問
botton 後端功能該如何寫
我已經把子畫面能夠顯示固定序號的內容
但前端寫入跳頁功能一直抓不到序號做對應

小魚 iT邦大師 1 級 ‧ 2018-03-21 12:40:28 檢舉
不用刪, 順便把你解決的方式分享一下吧.
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答