Monday, October 12, 2009

Grid,Comboe Bind...?

1) How to bind GridVIew ?
protected void Page_Load(object sender, EventArgs e)
{
BindUttarDetail();
}
private void BindUttarDetail()
{
gvUttaraDetail.DataSource = Emp.FillUttaraDetail();
gvUttaraDetail.DataBind();
}
protected void lbtnEdit_Click(object sender, EventArgs e)
{

}

2) Row DataBound Event
protected void gvUttaraDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.FindControl("lblDate");
DateTime dt = Convert.ToDateTime(lbl.Text);
lbl.Text = "AMit";
}
}

3)Bind Combo

public void BindMillCombo()
{
ddlMill.DataTextField = "MName";
ddlMill.DataValueField = "MID";
ddlMill.DataSource = Emp.FillCombo();
ddlMill.DataBind();
}

4) Connection String in Web.Config



providerName="System.Data.SqlClient" />



5) Delete Command or Edit Command

protected void lbtnDelete_Click(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
int Eid = Int32.Parse(lbtn.CommandArgument.ToString());
Emp.Delete(Eid, "Emp_Master", "Eid");
MultiView1.ActiveViewIndex = 1;
GridBind();
}

6) Grid Row Deleting Event

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values["EId"].ToString();
Response.Write(id);
}

7) Grid View in aspx side

ForeColor="#333333" GridLines="None" Width="100%">