从sql获取数据并将其显示在公告板中 [英] Fetch data from sql and display it in notice board

查看:94
本文介绍了从sql获取数据并将其显示在公告板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在使用c#从asp.net的sql server中获取数据时遇到问题。



详细信息: -



i想要从sql创建动态列表。喜欢布告牌或新的&活动。



i在sql表中有2列填充了4个条目,如

hi guys,

i have a problem in fetching a data from sql server in asp.net using c#.

details:-

i want to create a dynamic list from sql. like notice board or New & Events.

i have 2 column in sql table filling with a 4 entry like

Column1                 Column2
 A                         12
 B                         32
 C                         65
 D                         45



这就是我的餐桌。



i想要在主页上现场列1列表已经显示。当有人点击这个新页面时,已经打开了第2列数据只显示第一列的选定值。



谢谢


thats my table.

i want on home page onsite column1 list has been display. when some one is click on this new page has been open in which column 2 data has been show only selected value of column one.

thanks

推荐答案

使用GRIDVIEW

作为参考试试这个:



如何通过编码从sql数据库获取数据到gridview? [ ^
use GRIDVIEW
for reference try this :

how to get data from sql database to gridview by coding ?[^


使用gridview或repeater,并通过查询字符串中的id将href设置为另一个页面。
use gridview or repeater and set href to another page by taking "id" through query string.


您好



您可以使用网格视图并打开新页面使用查询字符串传递值并从那里获取与查询字符串对应的数据。



这是一个代码片段,可以帮助您...



在主页上创建一个这样的Gridview





Hello

You can use Grid view and for opening the new page use Query string to pass the value and get the data from there corresponding to the query string.

Here is a Code snippet to help you with...

On Home Page Create a Gridview like this


<asp:GridView ID="gdvBookedProduct" runat="server" AutoGenerateColumns="False" CellPadding="4"

                                        ForeColor="#333333" GridLines="None" Width="100%"

                                        HeaderStyle-HorizontalAlign="Left"

                                        onrowdatabound="gdvBookedProduct_RowDataBound">
                                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="First Column">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lnkFirstColumn" runat="server" Text="First Column Value" OnClick="lnkFirstColumn_Click" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                        <EditRowStyle BackColor="#999999" />
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                                    </asp:GridView>







On Home of Home Page






On Code behind of Home Page

protected void lnkDetails_Click(object sender, EventArgs e)
       {
           GridViewRow row = ((LinkButton)sender).Parent.Parent as GridViewRow;
           int r = row.RowIndex;
           string FirstColumnValue = gdvBookedProduct.Rows[r].Cells[0].Text.Trim();


           Response.Redirect("SecondPage.aspx?FistColumnValue=" + FirstColumnValue);


       }







第二页


使用Select Statement绑定另一个网格并将查询字符串传递到where条件。






On Second Page

Bind another grid with Select Statement and pass the query string to where condition.

  string FirstColumnValue= Request.QueryString.Get("FirstColumnValue");
SqlConnection con = new SqlConnection("");//connection name

               con.Open();
 
               SqlCommand cmd = new SqlCommand("select * from tablename where FirstColumn = " + FirstColumnValue , con);

 
               cmd.CommandType = CommandType.Text;
 
               SqlDataAdapter da = new SqlDataAdapter(cmd);
 
               DataSet ds = new DataSet();
 
               da.Fill(ds, "ss");
 
               dataGridView1.DataSource = ds.Tables["ss"]; ;







我认为这个解决方案会对你有所帮助。如有任何疑问,请随时回复。




I think this solution will help you. For any queries feel free to write back.


这篇关于从sql获取数据并将其显示在公告板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆