protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Create a new table.
DataTable taskTable = new DataTable("TaskList");
// Create the columns.
taskTable.Columns.Add("Id", typeof(int));
taskTable.Columns.Add("
Description", typeof(string));
taskTable.Columns.Add(" IsComplete", typeof(bool) );
//Add data to the new table.
for (int i = 0; i < 20; i++)
{
DataRow tableRow = taskTable.NewRow();
tableRow["Id"] = i;
tableRow["Description"] = "Task " + i.ToString();
tableRow["IsComplete"] = false;
taskTable.Rows.Add(tableRow);
}
//Persist the table in the Session object.
Session["TaskTable"] = taskTable;
//Bind data to the GridView control.
BindData();
}
}
protected void TaskGridView_ PageIndexChanging(object sender, GridViewPageEventArgs e)
{
TaskGridView.PageIndex = e.NewPageIndex;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
TaskGridView.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowCancelingEdit( object sender, GridViewCancelEditEventArgs e)
{
//Reset the edit index.
TaskGridView.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowUpdating( object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["TaskTable" ];
//Update the values.
GridViewRow row = TaskGridView.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex][" Id"] = ((TextBox)(row.Cells[1]. Controls[0])).Text;
dt.Rows[row.DataItemIndex][" Description"] = ((TextBox)(row.Cells[2]. Controls[0])).Text;
dt.Rows[row.DataItemIndex][" IsComplete"] = ((CheckBox)(row.Cells[3]. Controls[0])).Checked;
//Reset the edit index.
TaskGridView.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
private void BindData()
{
TaskGridView.DataSource = Session["TaskTable"];
TaskGridView.DataBind();
}
______________________________ ______________________________ ______________________________
protected void gvShowCategory_RowEditing( object sender, GridViewEditEventArgs e)
{
oCCategory = new CCategory();
Session["CategoryID"] = Convert.ToInt32( gvShowCategory.DataKeys[e. NewEditIndex].Value);
oCCategory.CategoryID = Convert.ToInt16(Session[" CategoryID"]);
//this method is used to Get Record from Translation_Category on the Basis of CategoryID
if (oCCategory. GetCategoryDetailByCategoryID( ))
{
txtCategoryName.Text = Convert.ToString(oCCategory. CategoryName);
txtCategoryDescription.Text = Convert.ToString(oCCategory. CategoryDescription);
}
}
protected void gvShowCategory_RowCommand( object sender, GridViewCommandEventArgs e)
{
oCCategory = new CCategory();
if (e.CommandName == "Delete")
{
oCCategory.CategoryID = Convert.ToInt32(e. CommandArgument);
//This Method is used to Delete Particular Record On the Basis of CategoryID
if (oCCategory.CheckDependences() )
{
if (!oCCategory.Dependences)
{
if (oCCategory.DeleteOldCategory( ))
{
Session["CategoryID"] = null;
txtCategoryName.Text = "";
txtCategoryDescription.Text = "";
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
lblMsg.Text = "Your Record Delete Sucessfully!";
// ClientScript. RegisterStartupScript(e. GetType(), "Message", "<script>alert('Your Record Delete Sucessfully !')</script>");
return;
}
}
else
{
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
lblMsg.Text = "Can't Delete This Record Because It is used in other Place!";
// ClientScript. RegisterStartupScript(e. GetType(), "Message", "<script>alert('Can't Delete This Record Because It is used in other Place !')</script>");
// return;
}
}
}
}
protected void gvShowCategory_Sorting(object sender, GridViewSortEventArgs e)
{
oCCategory = new CCategory();
string sortExpression = e.SortExpression;
ViewState["sortExpression"] = e.SortExpression;
// string direction = "ASC";
if (GridViewSortDirection == SortDirection.Ascending)
{
direction = "ASC";
//GridViewSortDirection = SortDirection.Descending;
}
else
{
direction = "DESC";
// GridViewSortDirection = SortDirection.Ascending;
}
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState[" sortDirection"];
}
set
{
ViewState["sortDirection"] = value;
}
{
if (!Page.IsPostBack)
{
// Create a new table.
DataTable taskTable = new DataTable("TaskList");
// Create the columns.
taskTable.Columns.Add("Id", typeof(int));
taskTable.Columns.Add("
taskTable.Columns.Add("
//Add data to the new table.
for (int i = 0; i < 20; i++)
{
DataRow tableRow = taskTable.NewRow();
tableRow["Id"] = i;
tableRow["Description"] = "Task " + i.ToString();
tableRow["IsComplete"] = false;
taskTable.Rows.Add(tableRow);
}
//Persist the table in the Session object.
Session["TaskTable"] = taskTable;
//Bind data to the GridView control.
BindData();
}
}
protected void TaskGridView_
{
TaskGridView.PageIndex = e.NewPageIndex;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
TaskGridView.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowCancelingEdit(
{
//Reset the edit index.
TaskGridView.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
protected void TaskGridView_RowUpdating(
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["TaskTable"
//Update the values.
GridViewRow row = TaskGridView.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["
dt.Rows[row.DataItemIndex]["
dt.Rows[row.DataItemIndex]["
//Reset the edit index.
TaskGridView.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
private void BindData()
{
TaskGridView.DataSource = Session["TaskTable"];
TaskGridView.DataBind();
}
______________________________
protected void gvShowCategory_RowEditing(
{
oCCategory = new CCategory();
Session["CategoryID"] = Convert.ToInt32(
oCCategory.CategoryID = Convert.ToInt16(Session["
//this method is used to Get Record from Translation_Category on the Basis of CategoryID
if (oCCategory.
{
txtCategoryName.Text = Convert.ToString(oCCategory.
txtCategoryDescription.Text = Convert.ToString(oCCategory.
}
}
protected void gvShowCategory_RowCommand(
{
oCCategory = new CCategory();
if (e.CommandName == "Delete")
{
oCCategory.CategoryID = Convert.ToInt32(e.
//This Method is used to Delete Particular Record On the Basis of CategoryID
if (oCCategory.CheckDependences()
{
if (!oCCategory.Dependences)
{
if (oCCategory.DeleteOldCategory(
{
Session["CategoryID"] = null;
txtCategoryName.Text = "";
txtCategoryDescription.Text = "";
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
lblMsg.Text = "Your Record Delete Sucessfully!";
// ClientScript.
return;
}
}
else
{
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
lblMsg.Text = "Can't Delete This Record Because It is used in other Place!";
// ClientScript.
// return;
}
}
}
}
protected void gvShowCategory_Sorting(object sender, GridViewSortEventArgs e)
{
oCCategory = new CCategory();
string sortExpression = e.SortExpression;
ViewState["sortExpression"] = e.SortExpression;
// string direction = "ASC";
if (GridViewSortDirection == SortDirection.Ascending)
{
direction = "ASC";
//GridViewSortDirection = SortDirection.Descending;
}
else
{
direction = "DESC";
// GridViewSortDirection = SortDirection.Ascending;
}
oCCategory.ShowAllCategory(ref gvShowCategory, sortExpression, direction);
}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["
}
set
{
ViewState["sortDirection"] = value;
}
}
______________________________ ______________________________ ___________________________
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
DataKeyNames="Id"
AutoGenerateColumns="false"
AutoGenerateEditButton="true"
Runat="server">
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<%# Eval("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
id="txtTitle"
Text='<%# Bind("Title") %>'
Runat="server" />
<asp:RequiredFieldValidator
id="valTitle"
ControlToValidate="txtTitle"
Text="(required)"
Runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id="ddlCategory"
DataSourceID=" srcMovieCategories"
DataTextField="Name"
DataValueField="Id"
SelectedValue='<%# Bind("CategoryId") %>'
Runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
______________________________ ______________________________ ______________________________ _
Acess Multiple DataKeys:----------
------------------------------ --sourabh---------------------
gdvApplications.DataKeys[ gdvApplications.SelectedIndex] .Values["name"];
gdvApplications.DataKeys[ gdvApplications.SelectedIndex] .Values["version"];
------------------------------ --sourabh---------------------
protected void OnRowCommand_ShowQuery(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "showQueryCommand")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e. CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
DataKey dk = this.queryGridControl. DataKeys[index];
int query_id = Convert.ToInt32(dk.Value);
}
}
------------------------------ -----------------------
Private Sub GridView1_ SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewSelectEventArgs) Handles GridView1. SelectedIndexChanging
Dim po As Integer = CInt(GridView1.DataKeys(e. NewSelectedIndex)("PO"))
Dim VendorID As Integer = CInt(GridView1.DataKeys(e. NewSelectedIndex)("VendorID"))
End Sub
------------------------------ -----------------------
protected void GridView1_ SelectedIndexChanged2
(object sender, EventArgs e)
string App_id =
GridView1.DataKeys[GridView1. SelectedIndex]
["ResponseID"].ToString();
SqlDataSource3. SelectParameters.Clear();
SqlDataSource3. SelectParameters.Add
("ResponseID", App_id);
DetailsView2.DataBind();
string Source_id =
GridView1.DataKeys[GridView1. SelectedIndex]
["Source_id"].ToString();
SqlDataSource4. SelectParameters.Clear();
SqlDataSource4. SelectParameters.Add
("Source_id", Source_id);
DetailsView3.DataBind();
}
------------------------------ -----------------------
gvwCourseStatus.DataKeys.Item( 0).Value
------------------------------ -----------------------
//Find Rows
protected void gvas_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
objCls_Category = new Cls_Category();
int ID = (int)gvas.DataKeys[e.RowIndex] .Value;
GridViewRow row = gvas.Rows[e.RowIndex];
if (row != null)
{
TextBox t = row.FindControl("txtCatNmae") as TextBox;
}
gvas.EditIndex = -1;
objCls_Category. ShowAllCategory(ref gvas);
}
______________________________
<asp:GridView
id="grdMovies"
DataSourceID="srcMovies"
DataKeyNames="Id"
AutoGenerateColumns="false"
AutoGenerateEditButton="true"
Runat="server">
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<%# Eval("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
id="txtTitle"
Text='<%# Bind("Title") %>'
Runat="server" />
<asp:RequiredFieldValidator
id="valTitle"
ControlToValidate="txtTitle"
Text="(required)"
Runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id="ddlCategory"
DataSourceID="
DataTextField="Name"
DataValueField="Id"
SelectedValue='<%# Bind("CategoryId") %>'
Runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
______________________________
Acess Multiple DataKeys:----------
------------------------------
gdvApplications.DataKeys[
gdvApplications.DataKeys[
------------------------------
protected void OnRowCommand_ShowQuery(Object sender,
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "showQueryCommand")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
DataKey dk = this.queryGridControl.
int query_id = Convert.ToInt32(dk.Value);
}
}
------------------------------
Private Sub GridView1_
Dim po As Integer = CInt(GridView1.DataKeys(e.
Dim VendorID As Integer = CInt(GridView1.DataKeys(e.
End Sub
------------------------------
protected void GridView1_
(object sender, EventArgs e)
string App_id =
GridView1.DataKeys[GridView1.
["ResponseID"].ToString();
SqlDataSource3.
SqlDataSource3.
("ResponseID", App_id);
DetailsView2.DataBind();
string Source_id =
GridView1.DataKeys[GridView1.
["Source_id"].ToString();
SqlDataSource4.
SqlDataSource4.
("Source_id", Source_id);
DetailsView3.DataBind();
}
------------------------------
gvwCourseStatus.DataKeys.Item(
------------------------------
//Find Rows
protected void gvas_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
objCls_Category = new Cls_Category();
int ID = (int)gvas.DataKeys[e.RowIndex]
GridViewRow row = gvas.Rows[e.RowIndex];
if (row != null)
{
TextBox t = row.FindControl("txtCatNmae") as TextBox;
}
gvas.EditIndex = -1;
objCls_Category.
}
No comments:
Post a Comment