使用数据列表重定向页面 [英] Redirection for a page using datalist
问题描述
你好,
我正在使用一个使用数据库填充的数据列表,如果我单击数据列表中的特定链接,是否可以重定向到不同的页面,即如果我单击链接,则有3种不同的服务(我将其作为链接制成,并从数据库填充)任何链接按钮,它重定向到单个页面,但我希望它重定向到其相应的页面.
我的数据库表
Hello,
I am using a datalist which is populated using database, is it possible to redirect to different pages if i click on particular link in datalist,i.e I am having 3 different services which i made as links, and populated from database, if i click on any link button it is redirecting to a single page,but i want it to redirect to their corresponding page.
My database table
CREATE TABLE MEDICALVOYAGER_BUSINESSUPLOAD_SERVICES
(BUSINESSUPLOAD_SERVICES_SERVICEID INT IDENTITY(1,1),
BUSINESSUPLOAD_SERVICES_SERVICENAME VARCHAR(100)PRIMARY KEY)
这是我的aspx页面,
Here is my aspx page,
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="datalist1" runat="server" OnItemCommand="abc">
<ItemTemplate>
<asp:LinkButton ID="link1" runat="server" CommandName="link1" >
<asp:Label ID="lbl1" runat="server" Text='<%#Eval("BUSINESSUPLOAD_SERVICES_SERVICENAME") %>' ></asp:Label>
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
我的CS页面
受保护的void Page_Load(对象发送者,EventArgs e)
{
SqlConnection con =新的SqlConnection(数据源= USER-PC \\ SQLEXPRESS;初始目录= MEDICALVOYAGER;集成安全性= True");
con.Open();
SqlDataAdapter da =新的SqlDataAdapter(从MEDICALVOYAGER_BUSINESSUPLOAD_SERVICES中选择BUSINESSUPLOAD_SERVICES_SERVICENAME",等等);
DataSet ds = new DataSet();
da.Fill(ds,"voy");
datalist1.DataSource = ds;
datalist1.DataBind();
con.Close();
}
受保护的void abc(对象源,DataListCommandEventArgs e)
{
如果(e.CommandName =="link1");
{
Response.Redirect("services.aspx");
}
}
请尽快帮我...
My CS page
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=MEDICALVOYAGER;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select BUSINESSUPLOAD_SERVICES_SERVICENAME from MEDICALVOYAGER_BUSINESSUPLOAD_SERVICES", con);
DataSet ds = new DataSet();
da.Fill(ds, "voy");
datalist1.DataSource = ds;
datalist1.DataBind();
con.Close();
}
protected void abc (object source, DataListCommandEventArgs e)
{
if (e.CommandName == "link1");
{
Response.Redirect("services.aspx");
}
}
Please help me asap...
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=MEDICALVOYAGER;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select BUSINESSUPLOAD_SERVICES_SERVICENAME from MEDICALVOYAGER_BUSINESSUPLOAD_SERVICES", con);
DataSet ds = new DataSet();
da.Fill(ds, "voy");
datalist1.DataSource = ds;
datalist1.DataBind();
con.Close();
}
}
更多信息:
http://stackoverflow.com/questions/3288686/datalist-in- asp-net-itemcommand-event-not-firing [ ^ ]
more info:
http://stackoverflow.com/questions/3288686/datalist-in-asp-net-itemcommand-event-not-firing[^]
这篇关于使用数据列表重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!