Hi ramco1917,
Please refer below sample.
SQL
CREATE TABLE [DataSet]
(
[Source] VARCHAR (20),
[InvoiceNumber] VARCHAR (20)
)
INSERT INTO [DataSet] VALUES ('Amazon','2315642')
INSERT INTO [DataSet] VALUES ('' ,'6584520')
INSERT INTO [DataSet] VALUES ('Others','8942315')
INSERT INTO [DataSet] VALUES ('Amazon','0325412')
INSERT INTO [DataSet] VALUES (NULL ,'6584522')
HTML
<asp:Repeater ID="rptDetails" runat="server" OnItemDataBound="rptDetails_ItemCommand">
<HeaderTemplate>
<table>
<tr>
<td>Source</td>
<td>InvoiceNumber</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Literal ID="ltrlSource" runat="server" Text='<%# Eval("Source") %>'></asp:Literal></td>
<td><asp:Literal ID="ltrlInvoice" runat="server" Text='<%# Eval("InvoiceNumber") %>'></asp:Literal></td>
<td><asp:HyperLink ID="lnkAmazon" runat="server" NavigateUrl="www.amazon.in" Text="Amazon"></asp:HyperLink></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namesapce
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Gridview();
}
}
private void Gridview()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM DataSet", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
rptDetails.DataSource = dt;
rptDetails.DataBind();
}
}
}
}
protected void rptDetails_ItemCommand(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem rptDetails = e.Item;
Literal ltrlInvoice = ((rptDetails.FindControl("ltrlInvoice")) as Literal);
Literal ltrlSource = ((rptDetails.FindControl("ltrlSource")) as Literal);
if (ltrlSource.Text == "Amazon")
{
HyperLink lnkAmazon = (HyperLink)e.Item.FindControl("lnkAmazon") as HyperLink;
lnkAmazon.NavigateUrl = "www.amazon.com/search=" + ltrlInvoice.Text;
lnkAmazon.Text = "www.amazon.com";
}
if (ltrlSource.Text != "Amazon")
{
HyperLink lnkAmazon = (HyperLink)e.Item.FindControl("lnkAmazon") as HyperLink;
lnkAmazon.NavigateUrl = "www.amazon.in/search=" + ltrlInvoice.Text;
lnkAmazon.Text = "www.amazon.in";
}
if (string.IsNullOrEmpty(ltrlSource.Text) || string.IsNullOrWhiteSpace(ltrlSource.Text))
{
HyperLink lnkAmazon = (HyperLink)e.Item.FindControl("lnkAmazon") as HyperLink;
lnkAmazon.Text = ltrlInvoice.Text;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.Gridview()
End If
End Sub
Private Sub Gridview()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT * FROM DataSet", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
rptDetails.DataSource = dt
rptDetails.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub rptDetails_ItemCommand(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rptDetails As RepeaterItem = e.Item
Dim ltrlInvoice As Literal = (TryCast((rptDetails.FindControl("ltrlInvoice")), Literal))
Dim ltrlSource As Literal = (TryCast((rptDetails.FindControl("ltrlSource")), Literal))
If ltrlSource.Text = "Amazon" Then
Dim lnkAmazon As HyperLink = TryCast(CType(e.Item.FindControl("lnkAmazon"), HyperLink), HyperLink)
lnkAmazon.NavigateUrl = "www.amazon.com/search=" & ltrlInvoice.Text
lnkAmazon.Text = "www.amazon.com"
End If
If ltrlSource.Text <> "Amazon" Then
Dim lnkAmazon As HyperLink = TryCast(CType(e.Item.FindControl("lnkAmazon"), HyperLink), HyperLink)
lnkAmazon.NavigateUrl = "www.amazon.in/search=" & ltrlInvoice.Text
lnkAmazon.Text = "www.amazon.in"
End If
If String.IsNullOrEmpty(ltrlSource.Text) OrElse String.IsNullOrWhiteSpace(ltrlSource.Text) Then
Dim lnkAmazon As HyperLink = TryCast(CType(e.Item.FindControl("lnkAmazon"), HyperLink), HyperLink)
lnkAmazon.Text = ltrlInvoice.Text
End If
End If
End Sub
Screenshot