Arrao4u

…a blog by Rama Rao

Archive for the ‘Gridview Rowcommand event’ Category

Gridview rowcommand event

Posted by arrao4u on February 22, 2010

<asp:ButtonField Text=”Edit” CommandName=”Select” ItemStyle-HorizontalAlign=”Left”>
<ItemStyle HorizontalAlign=”Left” />
</asp:ButtonField>

protected void grdBusinessType_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “Select”)
{
drpStatus.Enabled = true;
btnAdd.Text = “Update”;
int Id = Convert.ToInt32(grdBusinessType.DataKeys[int.Parse(e.CommandArgument.ToString())].Values[“Businessid”].ToString());
hdnID.Value = Id.ToString();
string BusinessType = grdBusinessType.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text;
ViewState[“BusinessType”] = BusinessType;

if (BusinessType.Equals(“&nbsp;”))
{
txtBusinessType.Text = “”;
}
else
{
if(BusinessType.Contains(“&amp”))
{
BusinessType = BusinessType.Replace(“amp”,””).ToString();
}
txtBusinessType.Text = BusinessType.Trim();
}
// string Status = hdnStatus.Value;
Label lblStatus = (Label)grdBusinessType.Rows[int.Parse(e.CommandArgument.ToString())].Cells[4].FindControl(“lblStatus”);
string Status = lblStatus.Text;
string strUserStatus = string.Empty;
if (Status != “”)
{
if ((Status.ToLower().Trim() == “n”) || (Status.ToLower().Trim() == “u”))
{
strUserStatus = “Active”;
}
else if (Status.ToLower().Trim() == “d”)
{
strUserStatus = “InActive”;
}
if (drpStatus.Items.FindByText(strUserStatus) != null)
{

drpStatus.ClearSelection();
int intCityIndex = drpStatus.Items.IndexOf(drpStatus.Items.FindByText(strUserStatus));
drpStatus.SelectedIndex = intCityIndex;

}
}

}
}

Posted in Gridview Rowcommand event | Leave a Comment »