Adding a link to the existing column in the gridview
Hello,In my project, gridview is binded from dataset. In which one of the column must be having a half of it as text and other half as link with a relative URL. It should be like below:
TEW 100 -----> "TEW" must be added programatically and 100 should be shown like link with relative URL .
I can't add a Bound field or template field to gridview, as this is a search page containing 8 textboxes depending upon search sql statements from different tables in database , gridview will be displayed .
By using below code , my output for that column is like 100 --->showing up like a text.
CodeBehind:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string finalsql = "";
finalsql = getSql(); // Method to get a sql
FillGrid();
}
}
protected void FillGrid()
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con); // sql will be coming getSql() method
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
int count = ds.Tables[0].Rows.Count;
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
grdTEW.DataSource = ds;
grdTEW.DataBind();
lblResults.Visible = true;
lblResults.Text= "Results for Search on " + sTitle_Search + ".";
lblMsg.Visible = false;
}
else
{
lblResults.Visible = true;
lblResults.Text = "Results for Search on " + sTitle_Search + ".";
lblMsg.Visible = true;
lblMsg.Text = "No records found for this search, please try again.";
grdTEW.DataSource = null;
}
}
ASPX code:
<asp:GridView ID="grdTEW" runat="server" > </asp:GridView>
Need some suggestions.
Thanks!!!!