|
Hi,
Once again from Chandrakanth.
Thanks for prompt reply.
Problem is when i click on Image button, CLIENT SIDE CODE is executing, next POST BACK is happening, C# CODE is executing.
Actually my problem is i want to avoid that POST BACK when i click on ASP:IMAGE BUTTON.
Any suggestion please............
Thanks and Regards
Chandrakanth
|
|
|
|
|
To Prevent the postback, you can return false in your clientscript - but this prevents the server-side-code from running.
You cannot simply avoid that postback. This means, you cannot simply
use the clientside AND SERVER-SIDE on-click events without a postback.
You can limit the effects this postback has by using updatepanels
and (if!ispostback..) code-blocks in your server-side code. You can also figure out, which control raised the postback.
BUT -
Maybe this is a solution to your problem? -
Hope this helps
|
|
|
|
|
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;
}
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
|
|
|
|
|
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
|
|
|
|
|
See next question answer....
|
|
|
|
|
1. Include your code in pre tags.
2. IMO, the inclusion of "GetGridViewData()" method in each & every event is creating problem. See if it works by removing that method from PageIndexChanging or Changed event.
|
|
|
|
|
Hi all,
I am developing an application with C # and ASP. I displays information in a GridView and I want to get my data select another GridView that is in another asp page.
I sought to know how do you fill the 2nd GridView. I think it must work with a query string, if someone can help me in this direction.
Thank you.
|
|
|
|
|
Use Session with Dataset/DataTable objects.
1st Page,
DataTable dtEmp = new DataTable();
Session["EmpData"] = dtEmp;
2nd Page,
DataTable dtResultEmp = new DataTable();
dtResultEmp = (DataTable)Session["EmpData"];
Now you can bind the Data to our 2nd Gridview on 2nd page.
|
|
|
|
|
iam also facing the same problem
in my gridview 1st colum is check box, then what ever user selects the checkboxes that data i have to transfer to next page grid
can you give example how to take all data in session or datatable
|
|
|
|
|
You need to loop through all rows of gridview.
Find those rows whose checkbox is checked, fill those records in a datatable.
Assign that datatable to a Session Variable as mentioned above.
Retrieve that session variable to a datatable on next page, as mentioned above.
Assign datatable of next page as datasource of 2nd gridview.
|
|
|
|
|
hi, i need while looping how to add to data table can you give some example which helps me
|
|
|
|
|
Your code is ok, just see the advice i have given in your original post.
|
|
|
|
|
if you can explain more this solution I can not apply, thank you
|
|
|
|
|
thatraja please, if you can detail your answer, I don't understand very well
|
|
|
|
|
I just noticed that the latest version of ASP.NET MVC has just been released. I have been developing in ASP.NET for over 6 years now, my question is why should i move to MVC, What are the advantages and how about the learning curve?
For those who are using it.. is it worth the investment in learning and using it?
What should i watch out for?
Can anyone help..
|
|
|
|
|
You should really google for this question. You will find A LOT of pros/cons lists and comparisons.
I especially recommend the video-sessions from scott hanselman. E.g.:
http://www.hanselman.com/blog/CategoryView.aspx?category=Channel9
You learn a lot and the presentation style keeps you awake easily.
Often mentioned pros/cons:
Pros:
- Clear seperation of concerns / architecture
- Programming the web as it's ment to be (there's no view-state imitating a stateful environment)
- Programming the web is suddenly more fun - no weird event-handling / viewstate
- Easy understandable conventions - less configuration.
- Powerful architecture and tools to reuse components/views
- Better support of unit-testing
- Powerful Tools help you create CRUD-Szenarios with amazing speed
-...
Cons:
- New concepts to learn, some are difficult to get used to for traditional webform-developers
- Rich webform UI controls can ususally not be used in MVC - and therefor have to be replaced somehow
- ...
I would go the following way:
- Learn the basics, whether you're planning on using MVC or not. Then you have
a good start to decide if it will help you in the future (or not). This knowledge is definitely not wasted.
- Have a look at the nerddinner-application from hanselman
Hope this helps at least a bit
|
|
|
|
|
Hi All,
when i am query from the data base i am getting Date in the following format
01-01-2010
but i want to display it in 01 - jan - 2010
how to this can any one help me.
Thanks and regards,
Amit Patel
|
|
|
|
|
For asp.net use <datetime>.ToString() with the suitable formatter from here .
And for MS SQL use Convert() function like here.
|
|
|
|
|
Hello,
when i change the quantity value and press update cart buttonn no chages happens and the cart quantities returns to 1 to all!!!
Here's th gridview
http://img15.imageshack.us/img15/2219/cartd.png
The Update Cart Event Handler and related methods
protected void UpdateCartButton_Click(object sender, EventArgs e)
{
System.Data.DataTable objDT = new System.Data.DataTable();
objDT = ((System.Data.DataTable)Session["Cart"]).Clone();
for (int i = 0; i <= ShoppingCartGridView.Rows.Count - 1; i++)
{
System.Data.DataRow drow = objDT.NewRow();
GridViewRow grow = ShoppingCartGridView.Rows[i];
string TempQ = ((TextBox)grow.FindControl("txtQuantity")).Text;
UpdateCartQuantities(i,TempQ);
BindTheGrid(ShoppingCartGridView);
}
}
public void UpdateCartQuantities(int rowIndex, string TempQ)
{
System.Data.DataTable CartTableForView =
(System.Data.DataTable)Session["cart"];
CartTableForView.Rows[rowIndex]["Quantity"] = TempQ;
Session["Cart"] = CartTableForView;
}
public void BindTheGrid(GridView TempGrid)
{
System.Data.DataTable CartTableForView = (System.Data.DataTable)Session["cart"];
TempGrid.DataSource = CartTableForView;
TempGrid.DataBind();
}
|
|
|
|
|
I am following http://msdn.microsoft.com/en-us/library/ms998360.aspx link to authenticate users against "actives directories" and i could successfully login using this method.
Can anyone help me out how exactly can i get details of all the users displayed in my web site application when i am logged in as Administrator.
I want to display user details when the user i.e.,Administrator clicks on link say "User Details"
|
|
|
|
|
Hi Guys,
I have a check box in my datagrid named chkSelection, also I have a bound column named phone_num
in the same datagrid. The issue is, I would like to get all the phone numbers
where a checkbox is checked...I have tried lots but can't get it right...
Anyone who knows such stuff? please help
Here is what I have tried but it won't work..
CheckBox chkSelection;
foreach (DataGridItem item in contacts.Items)
{
chkSelection = (CheckBox)item.FindControl("chkSelection");
if (chkSelection.Checked == true)
{
}
}
Thanks,
Mo
|
|
|
|
|
Are you able to find your checkbox using FindControl?
Try to quickwatch for DataGridItem to see is there checkbox available or not.
|
|
|
|
|
|
Thanks man, I tried to work through you article but
they are working on a gridview and it's not quiet the
same with a datagrid, for instance this line:
chkBoxIndex = (string)grdView.DataKeys[row.RowIndex].Value.ToString();
in a datagrid there is no [row.RowIndex]
and this is what is used to add all the row indexs to the arraylist.
do know anything relating to a datagrid in particular?
I appreciate your help man
|
|
|
|
|
The code seems ok to me, what problem are you facing?
Are you getting any error?
|
|
|
|
|