Click here to Skip to main content
14,733,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i have an trouble with to add a row in gridview at rowdatabound Event Actully i need to
add hyperlinks after each row in gridview

Example:
ITEM ID | ITEM | AMT
101 | A | 10000
LINK1 link2 link3
102 | B | 20000
LINK1 link2 link3


This type i really want
using ADDROW method not working
Posted
Comments
[no name] 28-Aug-14 2:07am
   
wht's ur code and where is ur problem
abhinavstar921 28-Aug-14 2:15am
   
>ASPX FILE

<script type="text/javascript" src="expander.js"></script>
<script type="text/javascript">
function divexpandcollapse(divname) {
var img = "img" + divname;
if ($("#" + img).attr("src") == "images/plus.png") {
$("#" + img)
.closest("tr")
.after("<tr><td></td><td colspan = '100%'>" + $("#" + divname)
.html() + "</td></tr>");
$("#" + img).attr("src", "images/minus.png");
} else {
$("#" + img).closest("tr").next().remove();
$("#" + img).attr("src", "images/plus.png");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdViewCustomers" runat="server" AutoGenerateColumns="False" DataKeyNames="CompanyName" onrowcreated="grdViewCustomers_RowCreated"
OnRowDataBound="grdViewCustomers_OnRowDataBound" CssClass="Grid" Height="276px"
Width="726px">
<columns>
<asp:BoundField ItemStyle-Width="150px" DataField="CompanyName"
HeaderText="Company Name" >
<itemstyle width="150px">

<asp:BoundField ItemStyle-Width="150px" DataField="Amt" HeaderText="Amount" >
<itemstyle width="150px">


<asp:BoundField DataField="Plan" HeaderText="PLAN TYPE" />
<asp:TemplateField>
<itemtemplate>
<asp:ImageButton ID="ImageButton1" runat="server" Height="36px"
ImageUrl="~/images/book.jpg" Width="98px" />

<HeaderTemplate>
BOOK
</HeaderTemplate>

<asp:TemplateField>
<HeaderTemplate>
DOWNLOAD FORM
</HeaderTemplate>



<asp:TemplateField ItemStyle-Width="20px">
<itemtemplate>

<img alt="Details" id="imgdiv<%# Eval("CompanyName") %>" src="images/plus.png" />

<div id="div<%# Eval("CompanyName") %>" style="display: none;">
<asp:GridView ID="grdViewOrdersOfCustomer" runat="server" AutoGenerateColumns="false" ShowHeader=false
DataKeyNames="CompanyName" CssClass="ChildGrid">
<columns>
<asp:BoundField ItemStyle-Width="150px" DataField="CompanyName" HeaderText="CompanyName" Visible=false/>
<asp:BoundField ItemStyle-Width="150px" DataField="Amt" HeaderText="Amount" />
<asp:BoundField ItemStyle-Width="150px" DataField="Plan" HeaderText="PlantType" />
<asp:TemplateField>
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" Height="36px"
ImageUrl="~/images/book.jpg" Width="98px" />

<HeaderTemplate>
BOOK
</HeaderTemplate>



</div>


<itemstyle width="20px">




<br />
 <br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="dt1" />
             
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="dt2" />
                     
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Bind" />
[no name] 28-Aug-14 2:20am
   
what for binding blank row
abhinavstar921 28-Aug-14 2:21am
   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public partial class NestedGridView : System.Web.UI.Page
{
DataTable dt1, dt2;
ArrayList arr;
int storid = 0;
int rowIndex = 1;
protected void Page_Load(object sender, EventArgs e)
{
dt1 = new DataTable();
dt2 = new DataTable();
arr = new ArrayList();

}
protected void Button3_Click(object sender, EventArgs e)
{

grdViewCustomers.DataSource = SelectData();
grdViewCustomers.DataBind();
}
private DataTable SelectData()
{
//string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SQLServerConnectionString"].ConnectionString;
//using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlQuery, connectionString))
//{
// DataTable dt = new DataTable("Customers");
// sqlDataAdapter.Fill(dt);
// return dt;
//}
DataTable dttemp = new DataTable();
dttemp = (DataTable)ViewState["dt11"];
return dttemp;
}
protected void grdViewCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
//hyperlink

// sub gridview
DataTable dtChild = new DataTable();
if (e.Row.RowType == DataControlRowType.DataRow)
{
string cName = grdViewCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
Response.Write(" " + cName.ToString());
GridView grdViewOrdersOfCustomer = (GridView)e.Row.FindControl("grdViewOrdersOfCustomer");
dtChild = filterCompany(cName);
if (dtChild.Rows.Count == 0)
{
e.Row.Cells[5].Visible = false;

}

storid = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Amt").ToString());

grdViewOrdersOfCustomer.DataSource =dtChild;
grdViewOrdersOfCustomer.DataBind();


}

}
protected void grdViewCustomers_RowCreated(object sender, GridViewRowEventArgs e)
{
bool newRow = true;
if ((storid > 0) && (DataBinder.Eval(e.Row.DataItem, "Amt") != null))
{
if (storid != Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Amt").ToString()))
newRow = true;
}
if ((storid > 0) && (DataBinder.Eval(e.Row.DataItem, "Amt") == null))
{
newRow = true;
rowIndex = 0;
}
if (newRow)
{
AddNewRow(sender, e);
}
}
public void AddNewRow(object sender, GridViewRowEventArgs e)
{
GridView grdViewCustomers = (GridView)sender;
GridViewRow NewTotalRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Insert);
NewTotalRow.Font.Bold = true;
NewTotalRow.BackColor = System.Drawing.Color.Aqua;
TableCell HeaderCell = new TableCell();
HeaderCell.Height = 10;
HeaderCell.HorizontalAlign = HorizontalAlign.Center;
HeaderCell.ColumnSpan = 4;
NewTotalRow.Cells.Add(HeaderCell);
grdViewCustomers.Controls[0].Controls.AddAt(e.Row.RowIndex + rowIndex, NewTotalRow);
rowIndex++;
}
private DataTable SelectSubData(string cname)
{
//dt1 = (DataTable)ViewState["dt11"];
dt2 = (DataTable)ViewState["dt12"];
DataTable dttemp=new DataTable();
dttemp.Reset();
dttemp.Columns.Add("CompanyName", typeof(string));
dttemp.Columns.Add("Amt", typeof(string));
dttemp.Columns.Add("Plan", typeof(string));


foreach (DataRow drt1 in dt1.Rows)
{
if (!arr.Contains(drt1[0].ToString()))
{
foreach (DataRow drt2 in dt2.Rows)
{

dttemp.Reset();
Thanks7872 28-Aug-14 2:12am
   
Not working means what? Where is the code you have implemented till now? What is the result and what is the expected result?
abhinavstar921 28-Aug-14 2:17am
   
actully grid is printed but no row created after each row that i really want
abhinavstar921 28-Aug-14 2:17am
   
Look At Example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900