如何在单击gridview中的超链接的标签中从数据库中获取数据 [英] how to fatch data from database in labels clicking on hyperlink in gridview
本文介绍了如何在单击gridview中的超链接的标签中从数据库中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hii all
我是谁。初学者.net。我想从包含u_id列名称的表中获取所需的数据..当我点击gridview的超链接时,fatch数据超链接包含与表列相同的u_id ..数据应该在标签的另一页中进行fatch ...相同的U_id ..
请帮助
提前感谢..
hii all
i m anil . beginner in .net. i want to fatch required data from a table that contains the u_id column name.. fatch data when i click the gridview's hyperlink that hyperlink contains u_id same as table column.. the data should be fatch in another page in labels..accroding to both same U_id..
please help
thanks in advance..
推荐答案
< asp:gridview id =GleaveReportrunat =serverbackcolor =Whitexmlns:asp =#unknown>
BorderColor = WhiteBorderStyle =RidgeBorderWidth =2pxCellPadding =3
CellSpacing =1GridLines =NoneAutoGenerateColumns =False
onrowdatabound =GleaveReport_RowDataBoundAllowPaging =False
AllowSorting =Falseonrowcommand =GleaveReport_RowCommand>
< footerstyle backcolor =#C6C3C6forecolor =Black >
< rowstyle backcolor =#DEDFDEforecolor =Black>
& LT;列> < asp:templatefield headertext =Auto No>
< itemtemplate>
< asp:linkbutton id =autonumoncommand =LinkButton_Clickrunat = servercommandargument =<%#Eval(u_id)=%& gt;=text =<%#Eval(u_id)%& gt;= >
< asp:templatefield headertext = EmpCodesortexpression =empcode>
< itemtemplate>
< asp:label id =empcoderunat =servertext =<% #Eval(empcode)%& gt;=>
< pagerstyle backcolor =#C6C3C6forecolor =Blackhorizontalalign =Right>
< SelectedRowStyle BackColor =#9471DEFont-Bold =TrueForeColor =White />
< HeaderStyle BackColor =#4A3C8CFont-Bold =TrueForeColor =#E7E7FF/>
代码落后
protected void LinkButton_Click(Object sender,CommandEventArgs e)
{
if(e.CommandArgument!= null)
{
Session [U_id ] = e.CommandArgument.ToString();
Response.Redirect(NewPage.aspx);
}
}
新页面
int auto = Convert.ToInt32(Session [U_id]。ToString());
我希望这对你有用
<asp:gridview id="GleaveReport" runat="server" backcolor="White" xmlns:asp="#unknown">
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" AutoGenerateColumns="False"
onrowdatabound="GleaveReport_RowDataBound" AllowPaging="False"
AllowSorting="False" onrowcommand="GleaveReport_RowCommand">
<footerstyle backcolor="#C6C3C6" forecolor="Black">
<rowstyle backcolor="#DEDFDE" forecolor="Black">
<columns> <asp:templatefield headertext="Auto No">
<itemtemplate>
<asp:linkbutton id="autonum" oncommand="LinkButton_Click" runat="server" commandargument="<%# Eval(" u_id")="" %>"="" text="<%# Eval(" u_id")%>"="">
<asp:templatefield headertext="EmpCode" sortexpression="empcode">
<itemtemplate>
<asp:label id="empcode" runat="server" text="<%# Eval(" empcode")%>"="">
<pagerstyle backcolor="#C6C3C6" forecolor="Black" horizontalalign="Right">
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
code behind
protected void LinkButton_Click(Object sender, CommandEventArgs e)
{
if (e.CommandArgument != null)
{
Session["U_id"] = e.CommandArgument.ToString();
Response.Redirect("NewPage.aspx");
}
}
For new page
int auto= Convert.ToInt32( Session["U_id"].ToString());
I hope this is useful to you
<asp:GridView ID="GleaveReport" runat="server" BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" AutoGenerateColumns="False"
onrowdatabound="GleaveReport_RowDataBound" AllowPaging="True"
AllowSorting="True" onpageindexchanging="GleaveReport_PageIndexChanging"
onrowcommand="GleaveReport_RowCommand"
onselectedindexchanged="GleaveReport_SelectedIndexChanged1">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<Columns>
<asp:templatefield headertext="Auto No">
<ItemTemplate>
<asp:linkbutton id="autonum" oncommand="LinkButton_Click" runat="server" commandargument='<%# Eval("U_id") %>' text='<%# Eval("U_id")%>'>
</asp:linkbutton>
</ItemTemplate>
</asp:TemplateField>
<asp:templatefield headertext="EmpCode" sortexpression="empcode">
<ItemTemplate>
<asp:label id="empcode" runat="server" text='<%# Eval("empcode")%>'></asp:label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
这篇关于如何在单击gridview中的超链接的标签中从数据库中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文