<script language="javascript">
document.getElementById("TextboxControlName").focus();
</script>
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{ //Get data row view
DataRowView drview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find dropdown control & get values
DropDownList dpEmpdept = (DropDownList)e.Row.FindControl("DrpDwnEmpDept");
string value = dpEmpdept.SelectedItem.Value;
//Find textbox control
TextBox txtname = (TextBox)e.Row.FindControl("txtName");
string Name = txtname.Text;
//Find checkbox and checked/Unchecked based on values
CheckBox chkb = (CheckBox)e.Row.FindControl("ChckBxActive");
if (drview[5].ToString() == "True")
{
chkb.Checked = true;
}
else
{
chkb.Checked = false;
}
}
}
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblPrice = (Label)e.Row.FindControl("lblPrice");
if (Convert.ToInt32(lblPrice.Text) > 100)
{
e.Row.ForeColor = System.Drawing.Color.Black;
e.Row.Font.Bold = true;
e.Row.BackColor = System.Drawing.Color.Brown;
}
}
}
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "self.MouseOverOldColor=this.style.backgroundColor;this.style.backgroundColor='#C0C0C0'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=self.MouseOverOldColor");
}
}
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList dp = (DropDownList)e.Row.FindControl("DrpDwnAddEmpDept");
dp.DataSource = GetEmpDept();
dp.DataTextField = "DepName";
dp.DataValueField = "DepName";
dp.DataBind();
}
}
private DataTable GetEmpDept()
{
//Get Employee department
DataTable dt = new DataTable();
dt.Columns.Add("DepName");
DataRow rw1 = dt.NewRow();
rw1[0] = "IT";
dt.Rows.Add(rw1);
DataRow rw2 = dt.NewRow();
rw2[0] = "Finance";
dt.Rows.Add(rw2);
DataRow rw3 = dt.NewRow();
rw3[0] = "Security";
dt.Rows.Add(rw3);
return dt;
}
<asp:GridView ID="GVSample" runat="server" AutoGenerateColumns="false" OnRowDataBound="GVSample_RowDataBound"> <Columns> <asp:TemplateField HeaderText="Userprofile"> <ItemTemplate> <asp:HyperLink ID="hyprlnkdetails" runat="server" /> <asp:Label ID="lblText" runat="server" Text=""></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink HLdetails = e.Row.FindControl("hyprlnkdetails") as HyperLink;
Label lblText = e.Row.FindControl("lblText") as Label;
if (drview[5].ToString()=="True")
{
HLdetails.Text = "Click here to view";
HLdetails.NavigateUrl = String.Format("~/details.aspx?UserID={0}", drview[8].ToString());
}
else
{
HLdetails.Visible = false;
lblText.Text = "View Restricted";
}
}
}
protected void GVSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string userID = GVSample.DataKeys[e.Row.RowIndex].Values[0].ToString();
}
}