Hi micah,
Please refer below code and modify as per your requirement.
HTML
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" OnDataBound="FormView1_DataBound">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
ID:
</td>
<td>
<asp:ImageButton ID="UserImage" ImageUrl='<%# "Images/" + Eval("Name") %>' ToolTip='<%#Eval("Name")%>'
Width="80px" Height="50px" runat="server" />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<asp:Label ID="lblUserName" Text='<%# Eval("UserName") %>' runat="server" />
</td>
</tr>
<tr>
<td>
Email Id:
</td>
<td>
<%# Eval("Email") %>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="btnAdd" Visible="false" runat="server">Add</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="btnEdit" Visible="false" runat="server">Edit</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</div>
</form>
C#
private string constring = ConfigurationManager.ConnectionStrings["constring"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetData();
}
}
private void GetData()
{
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM [User] INNER Join Files On Files.UserName=[User].UserName WHERE [user].UserName=@UserName", con))
{
cmd.Parameters.AddWithValue("@UserName", Request.QueryString["UserName"].ToString());
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
FormView1.DataSource = dt;
FormView1.DataBind();
}
}
}
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.Row.RowType == DataControlRowType.DataRow)
{
string username = (FormView1.Row.FindControl("lblUserName") as Label).Text;
if (username == Session["UserName"].ToString())
{
(FormView1.Row.FindControl("btnEdit") as LinkButton).Visible = true;
}
else
{
(FormView1.Row.FindControl("btnAdd") as LinkButton).Visible = true;
}
}
}
Vb.net
Private constring As String = ConfigurationManager.ConnectionStrings("constring").ToString()
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Me.GetData()
End If
End Sub
Private Sub GetData()
Using con As New SqlConnection(constring)
con.Open()
Using cmd As New SqlCommand("SELECT * FROM [User] INNER Join Files On Files.UserName=[User].UserName WHERE [user].UserName=@UserName", con)
cmd.Parameters.AddWithValue("@UserName", Request.QueryString("UserName").ToString())
cmd.CommandType = CommandType.Text
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
FormView1.DataSource = dt
FormView1.DataBind()
End Using
End Using
End Sub
Protected Sub FormView1_DataBound(sender As Object, e As EventArgs)
If FormView1.Row.RowType = DataControlRowType.DataRow Then
Dim username As String = TryCast(FormView1.Row.FindControl("lblUserName"), Label).Text
If username = Session("UserName").ToString() Then
TryCast(FormView1.Row.FindControl("btnEdit"), LinkButton).Visible = True
Else
TryCast(FormView1.Row.FindControl("btnAdd"), LinkButton).Visible = True
End If
End If
End Sub
Screenshot