How to display column values from database as link in asp page

Posted by Oswaldlily under ASP.NET on 1/12/2012 | Points: 10 | Views : 7688 | Status : [Member] | Replies : 6
<asp:LinkButton ID="lnk1" runat="server" onclick="CallMe"></asp:LinkButton><br />
<asp:LinkButton ID="lnk2" runat="server" onclick="CallMe"></asp:LinkButton><br />
<asp:LinkButton ID="lnk3" runat="server" onclick="CnllMe"></asp:LinkButton><br />

In codebehind

DateTime dt = System.DateTime.Now.AddDays(3);
this.lnkdate1.Text = dt.AddDays(1).ToShortDateString();
this.lnkdate2.Text = dt.AddDays(2).ToShortDateString();
this.lnkdate3.Text = dt.AddDays(3).ToShortDateString();
this.lnkdate4.Text = dt.AddDays(4).ToShortDateString();
this.lnkdate5.Text = dt.AddDays(5).ToShortDateString();



which displays date from
2012/01/17
2012/01/18
2012/01/19
2012/01/20
2012/01/21

If this date not present in database i don want to display
In database,i have one column in table which displays some other date which has nearly 500 dates




Responses

Posted by: Sksamantaray on: 1/13/2012 [Member] Silver | Points: 25

Up
0
Down
  <asp:TemplateField HeaderText="Posted Questions"  >


<ItemTemplate>
<asp:LinkButton ID="lblTopicHeading" CssClass="linkBtn" runat="server" Text= '<%# Bind("column1 ") %>' />

</ItemTemplate>

</asp:TemplateField>


Try this putting in gridview.

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ogipansrk on: 1/13/2012 [Member] Starter | Points: 25

Up
0
Down
foreach (DataRow myrow in dt1.Rows)
{

LinkButton link = new LinkButton();
link.ID = "lb" + myrow["Text"].ToString();
link.Text = myrow["Text"].ToString();
link.PostBackUrl = myrow["Link"].ToString();
Panel1.Controls.Add(link);

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/13/2012 [Member] Bronze | Points: 25

Up
0
Down
If u want to redirect the values to Onther page or Same page by clicking on link button then change the name of your page as u needed in href section.
I a grid View Company Name will be displayed as a Hyperlink by clicking into link which will redirect to specified page along with company ID where you can display specific id rows from DB.
<ItemTemplate>

<a href="Company.aspx?id=<%#Eval("ID")%>">
<asp:Label ID="lblCompany" runat="server" Text='<%#Eval("CompanyName") %>'></asp:Label>
</a>
</ItemTemplate>


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/13/2012 [Member] Silver | Points: 25

Up
0
Down
<ItemTemplate>
<a href ='<%#"TargetPage.aspx?Value="+DataBinder.Eval(Container.DataItem,"column1") %>'><%#Eval("column1") %> </a>
</ItemTemplate>

//another way to directly go to target page paasing value

Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 1/13/2012 [Member] Starter | Points: 25

Up
0
Down
@Sksamantaray
Sksamantaray

I followed oly your code...
see here this displays in linkbutton
2012/01/17
2012/01/18
2012/01/19
2012/01/20
2012/01/21

if 2012/01/19 is not in database ,instead it should come as
2012/01/17
2012/01/18
2012/01/20
2012/01/21
2012/01/22

understand?

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/13/2012 [Member] Silver | Points: 25

Up
0
Down
ok

Create a Loop which has to run because there are 5 Link buttons which will get 5 date values.
Create a 2nd loop which has to run until it get a matching input date in database, when matched , Add the text , check the external loops value
ex: if 0 add the value to Linkbutton1, if 1 add the date value to Linkbutton , if 4 add the value to LinkButton5, then break the loop and go back to external loop;
Like this external loop will execute 5 times and 5 matchig date value will be added to your linkbuttons

for(i=0;i<5;i++)
{
for(............)
{
pass your date value to sql storprocedure here
when matched check the external loops value here and add the date to desired linkbutton
and break inner loop
}
}


Thanks,
Sanjay

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response