Reputation: 31
I tried many work around but unable to set the column as hyperlink. This is the output i get. Output that i get
I want to add the hyperlink as below screenshot:
Click on that link able to show the detail as below
This is my code but i unable to add hyperlink:
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat = "server" AutoGenerateColumns="false" OnDataBound="OnDataBound" GridLines="Both">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="150" />
<asp:BoundField DataField="LOT" HeaderText="LOT" ItemStyle-Width="150" />
<asp:BoundField DataField="TYPE" HeaderText="TYPE" ItemStyle-Width="150" />
<asp:BoundField DataField="KEY" HeaderText="KEY" ItemStyle-Width="150" />
<asp:BoundField DataField="VALUE" HeaderText="VALUE" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
Code behind that i have done:
protected void btn_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DateTime StartDate = Convert.ToDateTime(datepickerstart.Text);
string Date = StartDate.ToString("dd-MMM-yyyy");
DateTime EndDate = Convert.ToDateTime(datepicker.Text);
string dt2 = EndDate.ToString("dd-MMM-yyyy");
GridView1.DataSource = GetData("Oracle query");
GridView1.DataBind();
txtDate.Text = "You Selected Start:" + Date;
txtDate1.Text = "You Selected End:" + EndDate;
}
private DataTable GetData(string query)
{
string oradb = "Data Source=(DESCRIPTION =" +
"(ADDRESS = (PROTOCOL=TCP)(HOST = '')(PORT = ''))" +
"(CONNECT_DATA =" +
"(SERVER = DEDICATED)" +
"(SERVICE_NAME = '')" +
")" +
");User ID='';Password='';";
DataTable dt = new DataTable();
OracleConnection conn = new OracleConnection(oradb);
using (OracleConnection con = new OracleConnection(oradb))
{
using (OracleCommand cmd = new OracleCommand(query))
{
using (OracleDataAdapter sda = new OracleDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}
protected void OnDataBound(object sender, EventArgs e)
{
for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = GridView1.Rows[rowIndex];
GridViewRow previousRow = GridView1.Rows[rowIndex + 1];
if (row.Cells[0].Text == previousRow.Cells[0].Text)
{
row.Cells[0].RowSpan = previousRow.Cells[0].RowSpan < 2 ? 2 :
previousRow.Cells[0].RowSpan + 1;
previousRow.Cells[0].Visible = false;
}
}
}
}
Upvotes: 0
Views: 1116
Reputation: 2603
Instead of Bound Field you need to use TemplateField > ItemTemplate > LinkButton just i have used below:
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White" runat = "server" AutoGenerateColumns="false" OnDataBound="OnDataBound" GridLines="Both">
<Columns>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnIdLink" runat="server" Text='<%# Bind("ID") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LOT" HeaderText="LOT" ItemStyle-Width="150" />
<asp:BoundField DataField="TYPE" HeaderText="TYPE" ItemStyle-Width="150" />
<asp:BoundField DataField="KEY" HeaderText="KEY" ItemStyle-Width="150" />
<asp:BoundField DataField="VALUE" HeaderText="VALUE" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
Upvotes: 1