Click here to Skip to main content
15,905,508 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionHow to avoid postback of ASP: Image Button Pin
ChandrakanthGaddam14-Apr-10 1:50
ChandrakanthGaddam14-Apr-10 1:50 
AnswerRe: How to avoid postback of ASP: Image Button Pin
saini arun14-Apr-10 1:52
saini arun14-Apr-10 1:52 
GeneralRe: How to avoid postback of ASP: Image Button Pin
ChandrakanthGaddam14-Apr-10 2:30
ChandrakanthGaddam14-Apr-10 2:30 
AnswerRe: How to avoid postback of ASP: Image Button Pin
michaelschmitt14-Apr-10 2:38
michaelschmitt14-Apr-10 2:38 
GeneralRe: How to avoid postback of ASP: Image Button Pin
ChandrakanthGaddam14-Apr-10 2:58
ChandrakanthGaddam14-Apr-10 2:58 
GeneralRe: How to avoid postback of ASP: Image Button Pin
michaelschmitt14-Apr-10 3:25
michaelschmitt14-Apr-10 3:25 
Questiontransfering data from one gridview to another gridview page Pin
developerit14-Apr-10 0:53
developerit14-Apr-10 0:53 
Questiontransfering data from one gridview to another page gridview Pin
developerit14-Apr-10 0:10
developerit14-Apr-10 0:10 
hi iam using asp.net with c#, my grid contains 1st column is check box ,and paging is true ,iam displaying data from view that does not contain primary key, so based on this when user selects the no of checkboxes in 1st page and
in another page some records then i want to transfer to another page gridview but it is not displaying. can you correct my code where iam going wrong


string constr = "Data Source=MAINSERVER;Initial Catalog=Inventory;User ID=sa;Password=nsg";
protected void Page_Load(object sender, EventArgs e)
{


if(Page.IsPostBack==false)
{
GridView1.PageIndex = 0;

bindata();

}


}

private void bindata()
{

SqlConnection con12 = new SqlConnection(constr);
SqlDataAdapter da12 = new SqlDataAdapter("SELECT [CategoryNameE], [ItemKey], [ItemKeyNameE], [CurrentQTY], [SalesPrice] FROM [CurrentInWH]", con12);
DataSet ds = new DataSet();
da12.Fill(ds,"t");
GridView1.DataSource = ds.Tables["t"];
GridView1.DataBind();
}



private void GetGridViewData()
{
DataTable dt;
if (ViewState["CheckedRecords"] != null)
dt = (DataTable)ViewState["CheckedRecords"];
else
dt = CreateNewTable();

for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chk");
if (chk.Checked)
{
dt = AddNewRow(GridView1.Rows[i], dt);
}
else
{
dt = RemoveRow(GridView1.Rows[i], dt);
}

}
ViewState["CheckedRecords"] = dt;
}
//@CategoryNameE,@ItemKey,@ItemKeyNameE,@CurrentQTY,@SalesPrice,@Quantity,@Total

private DataTable CreateNewTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("CategoryNameE");
dt.Columns.Add("ItemKey");
dt.Columns.Add("ItemKeyNameE");
dt.Columns.Add("CurrentQTY");
dt.Columns.Add("SalesPrice");
dt.Columns.Add("Quantity");
dt.Columns.Add("Total");

dt.AcceptChanges();
return dt;
}


private DataTable AddNewRow(GridViewRow gvRow, DataTable dt)
{
DataRow[] dr = dt.Select("CustomerID = '" + gvRow.Cells[1].Text + "'");
if (dr.Length <= 0)
{
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["CategoryNameE"] = gvRow.Cells[1].Text;
dt.Rows[dt.Rows.Count - 1]["ItemKey"] = gvRow.Cells[2].Text;
dt.Rows[dt.Rows.Count - 1]["ItemKeyNameE"] = gvRow.Cells[3].Text;
dt.Rows[dt.Rows.Count - 1]["CurrentQTY"] = gvRow.Cells[4].Text;
dt.Rows[dt.Rows.Count - 1]["SalesPrice"] = gvRow.Cells[5].Text;
dt.Rows[dt.Rows.Count - 1]["Quantity"] = gvRow.Cells[6].Text;
dt.Rows[dt.Rows.Count - 1]["Total"] = gvRow.Cells[7].Text;



dt.AcceptChanges();
}
return dt;
}


private DataTable RemoveRow(GridViewRow gvRow, DataTable dt)
{
DataRow[] dr = dt.Select("CategoryNameE= '" + gvRow.Cells[1].Text + "'");
if (dr.Length > 0)
{
dt.Rows.Remove(dr[0]);
dt.AcceptChanges();
}
return dt;
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GetGridViewData();
GridView1.PageIndex = e.NewPageIndex;
bindata();
foreach (GridViewRow row in GridView1.Rows)
{


CheckBox c1 = (CheckBox)row.FindControl("chk");
TextBox qt = (TextBox)row.FindControl("txtqty");
TextBox tot1 = (TextBox)row.FindControl("txttot");

Label categoryname = (Label)row.FindControl("Label5");
Label ItemKey = (Label)row.FindControl("Label2");
Label ItemKeyNameE = (Label)row.FindControl("Label1");
Label CurrentQTY = (Label)row.FindControl("Label3");
Label SalesPrice = (Label)row.FindControl("Label4");




if (c1.Checked == true)
{
clsdataset.insert(categoryname.Text, ItemKey.Text, ItemKeyNameE.Text, CurrentQTY.Text, SalesPrice.Text, qt.Text, tot1.Text);




}




}
}



protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{

GetGridViewData();



}



protected void chk_CheckedChanged(object sender, EventArgs e)
{

GetGridViewData();
TextBox txtqty1;TextBox txttott;CheckBox ch=null;
for (int i = 0; i < GridView1.Rows.Count; i++)
{

txtqty1 = (TextBox)GridView1.Rows[i].FindControl("txtqty");
txttott = (TextBox)GridView1.Rows[i].FindControl("txttot");
ch=(CheckBox)GridView1.Rows[i].FindControl("chk");

if (ch.Checked)
{
txtqty1.Visible = true;
txttott.Visible = true;
}
else {

txtqty1.Visible = false;
txttott.Visible = false;

}




}

this is insertbutton code
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{


CheckBox c1 = (CheckBox)row.FindControl("chk");
TextBox qt = (TextBox)row.FindControl("txtqty");
TextBox tot1 = (TextBox)row.FindControl("txttot");

Label categoryname = (Label)row.FindControl("Label5");
Label ItemKey = (Label)row.FindControl("Label2");
Label ItemKeyNameE = (Label)row.FindControl("Label1");
Label CurrentQTY = (Label)row.FindControl("Label3");
Label SalesPrice = (Label)row.FindControl("Label4");

if (c1.Checked == true)
{
clsdataset.insert(categoryname.Text, ItemKey.Text, ItemKeyNameE.Text, CurrentQTY.Text, SalesPrice.Text, qt.Text, tot1.Text);




}


}


iam performing this operation inbutton1 for saving all records but it is not storing previous records
AnswerRe: transfering data from one gridview to another page gridview Pin
Sandesh M Patil14-Apr-10 0:32
Sandesh M Patil14-Apr-10 0:32 
AnswerRe: transfering data from one gridview to another page gridview Pin
nagendrathecoder14-Apr-10 0:37
nagendrathecoder14-Apr-10 0:37 
QuestionFill a GridView to select data from a GridView Pin
tek 200913-Apr-10 23:13
tek 200913-Apr-10 23:13 
AnswerRe: Fill a GridView to select data from a GridView Pin
thatraja13-Apr-10 23:21
professionalthatraja13-Apr-10 23:21 
GeneralRe: Fill a GridView to select data from a GridView Pin
developerit13-Apr-10 23:56
developerit13-Apr-10 23:56 
GeneralRe: Fill a GridView to select data from a GridView Pin
nagendrathecoder14-Apr-10 0:12
nagendrathecoder14-Apr-10 0:12 
GeneralRe: Fill a GridView to select data from a GridView Pin
developerit14-Apr-10 0:56
developerit14-Apr-10 0:56 
GeneralRe: Fill a GridView to select data from a GridView Pin
nagendrathecoder14-Apr-10 2:05
nagendrathecoder14-Apr-10 2:05 
GeneralRe: Fill a GridView to select data from a GridView Pin
tek 200914-Apr-10 4:44
tek 200914-Apr-10 4:44 
GeneralRe: Fill a GridView to select data from a GridView Pin
tek 200914-Apr-10 2:07
tek 200914-Apr-10 2:07 
QuestionWhy ASP.NET MVC? Pin
Clement Siby13-Apr-10 22:20
Clement Siby13-Apr-10 22:20 
AnswerRe: Why ASP.NET MVC? Pin
michaelschmitt14-Apr-10 2:03
michaelschmitt14-Apr-10 2:03 
QuestionDateTime Problem Pin
Amit Patel198513-Apr-10 21:59
Amit Patel198513-Apr-10 21:59 
AnswerRe: DateTime Problem Pin
saini arun13-Apr-10 22:10
saini arun13-Apr-10 22:10 
QuestionProblem with Gridview - Shopping cart Pin
EmZan13-Apr-10 21:26
EmZan13-Apr-10 21:26 
QuestionHow to get details of users in active directories using LDAP Pin
roshankamath13-Apr-10 20:50
roshankamath13-Apr-10 20:50 
QuestionCheckbox in datagrid Pin
Morgs Morgan13-Apr-10 20:19
Morgs Morgan13-Apr-10 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.