Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

SQL
CREATE TABLE MEDICALVOYAGER_BUSINESSUPLOAD_SERVICES
(BUSINESSUPLOAD_SERVICES_SERVICEID INT IDENTITY(1,1),
BUSINESSUPLOAD_SERVICES_SERVICENAME VARCHAR(100)PRIMARY KEY)




Here is my aspx page,

XML
<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>


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...
Posted
Comments
[no name] 9-Jul-12 0:26am    
you need to show sample data of your table.
prateekfgiet 9-Jul-12 0:57am    
if you want to call 3 service related to link1 data "BUSINESSUPLOAD_SERVICES_SERVICENAME"
you can use window.open() for all services it will open new pages related to data.

1 solution

C#
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();
 
    }
}


more info:
http://stackoverflow.com/questions/3288686/datalist-in-asp-net-itemcommand-event-not-firing[^]
 
Share this answer
 
v2
Comments
shabadiveda 12-Jul-12 22:30pm    
i solved by mysely thnx.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900