Any My Code Behind file
private void FirstName_DataBinding(Object sender, EventArgs e)
{
// Get the Label control to bind the value. The Label control
// is contained in the object that raised the DataBinding event (the sender parameter).
Label l = (Label)sender;
// Get the GridViewRow object that contains the Label control.
GridViewRow row = (GridViewRow)l.NamingContainer;
// Get the field value from the GridViewRow object and assign it to the Text property of the Label control.
l.Text = DataBinder.Eval(row.DataItem, "Links").ToString();
}
private void LastName_DataBinding(Object sender, EventArgs e)
{
// Get the Label control to bind the value. The Label control
// is contained in the object that raised the DataBinding event (the sender parameter).
Label l = (Label)sender;
// Get the GridViewRow object that contains the Label control.
GridViewRow row = (GridViewRow)l.NamingContainer;
// Get the field value from the GridViewRow object and assign it to the Text property of the Label control.
l.Text = DataBinder.Eval(row.DataItem, "Links1").ToString();
}
}
and her's my.cs file
protected void Page_Load(object sender, EventArgs e)
{
////Populate Data
DataTable dt = new DataTable();
dt.Columns.Add("Links");
dt.Columns.Add("Links1");
DataRow dr;
for (int i = 1; i < 10; i++)
{
dr = dt.NewRow();
dr["Links"] = "A" + i;
dr["Links1"] = "B" + i;
dt.Rows.Add(dr);
dt.AcceptChanges();
}
////Grid view
// The field columns need to be created only when the page is first loaded.
if (!IsPostBack)
{
gvTest.AutoGenerateColumns = false;
// Dynamically create field columns to display the desired
// fields from the data source. Create a TemplateField object
// to display an author's first and last name.
TemplateField customField = new TemplateField();
// Create the dynamic templates and assign them to
// the appropriate template property.
for (int i = 0; i < 10; i++)
{
customField = new TemplateField();
customField.HeaderTemplate = new MyGridViewTemplate(DataControlRowType.Header,i.ToString());
customField.ItemTemplate = new MyGridViewTemplate(DataControlRowType.DataRow,i.ToString());
// Add the field column to the Columns collection of the GridView control.
this.gvTest.Columns.Add(customField);
}
// Add the field column to the Columns collection of the GridView control.
this.gvTest.Columns.Add(customField);
BoundField boundField = new BoundField();
boundField.HeaderText = "Bug ID";
boundField.DataField = "Links";
this.gvTest.Columns.Add(boundField);
gvTest.DataSource = dt;
gvTest.DataBind();
}
}
protected void ButtonShow(object sender, EventArgs e)
{
foreach (GridView grow in gvTest.Rows)
{
DropDownList ddl = (DropDownList)grow.FindControl("ddl");
}
}
Surajemo, if this helps please login to Mark As Answer. | Alert Moderator