|
//Default.aspx
protected void Button1_Click(object sender, EventArgs e)
{
Session["A"] = GridView1.Columns["A"];
Server.Transfer("NewPage.aspx");
}
//Result.aspx
protected void Page_Load(object sender, EventArgs e)
{
GridViewColumn col = (GridViewColumn)Session["A"];
GridView2.Columns.Add(col);
}
|
|
|
|
|
You don't store presentation objects and pass them around. Have you even tried this? I doubt it very much
only two letters away from being an asset
|
|
|
|
|
ashutosh_karna wrote: how can I pass the whole gridview as session varaible
You don't want to do that. GridView is just a presentation of the data. You don't pass textboxes and other such controls between pages do you?
Allow the users to fill in the data, save it, then transfer to the next page, retrieve the data and present it on that page.
In anticipation of the line of thought, no you don't want to save the DataSet, or whatever storage object you are using, in session state either. A DataSet can take quite a bit of memory depending on what is in it, it wouldn't scale very well.
only two letters away from being an asset
|
|
|
|
|
The code above actually saves the data in a session. If he doesn't want to do the saving in the first page better save data into a Session and retrieve in the second page. Less burden on the Database too.
|
|
|
|
|
Ibrahim Bello wrote: Less burden on the Database too.
And when the data being stored in session is large or the number of concurrent users is high?
only two letters away from being an asset
|
|
|
|
|
No, surely not
If that is the case (and he hasn't said whether it is) saving to database will be better.
|
|
|
|
|
(VS 2005)
I need to display a set of parts to be loaded on a truck for shipping.
After the parts are loaded on to the truck the actual number of parts is entered back into the system in a simple data entry fashion.
All of the columns should be ReadOnly=True except the Quantity Loaded field: QtyLoaded.
I want the field to be editable when the page is presented. No "Edit" links should be required since all rows in this column should be entered.
I created this asp code, with ReadOnly=False on the QtyLoaded field and it still will not let me edit this field. Is there something I am missing here?
-----------------------
<asp:gridview id="GridView1" autogeneratecolumns="False" runat="server">
<asp:boundfield datafield="QtyRequired" headertext="QtyRequired" readonly="True">
<asp:boundfield datafield="QtyUsed" headertext="Qty Used" ><="" asp:boundfield="">
<asp:boundfield datafield="QtyRemaining" headertext="Qty Remaining" ><="" asp:boundfield="">
<asp:boundfield datafield="QtyLoaded" headertext="Qty Loaded" readonly="False">
<asp:boundfield datafield="PartNumberDesc" headertext="Description">
<asp:BoundField DataField="PartNumber" HeaderText="Part Number">
-----------
Thanks
Chuck
|
|
|
|
|
Yes. If you want a field to be editable, use a template column and and a textbox or something like that.
I didn't get any requirements for the signature
|
|
|
|
|
Todd, thanks for answering...
Here is the same code except I have changed the BoundField QtyLoaded to a TemplateField.
Please tell me what I have done wrong. This field just appears as a blank non-editable field (Column).
<columns>
<asp:boundfield="" datafield="QtyRequired" headertext="QtyRequired" readonly="True">
<asp:boundfield datafield="QtyUsed" headertext="Qty Used">
<asp:templatefield headertext="Qty Loaded">
<edititemtemplate>
<asp:textbox runat="server" id="txtQtyLoaded" text="<%# DataBinder.Eval(Container, "Qtyloaded") %>">
<asp:boundfield datafield="PartNumberDesc" headertext="Description" ><="" asp:boundfield="">
<asp:boundfield datafield="PartNumber" headertext="Part Number">
Thanks again
Chuck...
|
|
|
|
|
<asp:templatefield headertext="Qty Loaded">
<asp:itemtemplate>
<asp:textbox runat="server" id="txtQtyLoaded" text="<%# DataBinder.Eval(Container, "Qtyloaded") %>">
<asp:itemtemplate>
I didn't get any requirements for the signature
|
|
|
|
|
Todd,
When I used EditItemTemplate
the QtyLoaded field was recognized.
With your change here is the error that I am getting:
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message="DataBinding: 'System.Web.UI.WebControls.GridViewRow' does not contain a property with the name 'QtyLoaded'."
Source="System.Web"
StackTrace:
at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
at System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
at System.Web.UI.DataBinder.Eval(Object container, String expression)
at ASP.inventory_materialloadtruck_aspx.__DataBinding__control27(Object sender, EventArgs e) in C:\WorkOrders\Inventory\MaterialLoadTruck.aspx:line 66
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
Please advise!
Chuck...
|
|
|
|
|
Hello friends
I want to create a forum using asp.net just like one can make using joomla
or wordpress.
I have never made any. So I don't have much idea. But I need to do this asap.
If there is any code or example or any sort of thing that will help me making this please let me know.
Thanking in advance
Johnny
|
|
|
|
|
You need to read the link in my sig. It explains what you need to know.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
I have a table "custmsgrecieved" with columns as-
CustId,Message,DateofMsg,Subject,Status,FromBrokerId(may have NULL value),FromAdminId,MsgId(may have NULL value)
I have a gridview with diff columns.One of column is binded with "Name".This "Name" is defined below in sql quey.I have to pick up this table in my gridview.I have a query-
"select cust.*,brok.FirstName+' '+brok.LastName as Name,
from custmsgrecieved as cust,brokerdetails as brok
where cust.CustId='1001' and brok.BrokerId=cust.FromBrokerId"
here "brokerdetails" is another table which contains BrokerId,FirstName,LastName as columns.
Now problem is arising that when there is a NULL value in FromBrokerId in custmsgrecieved table then that row is not appearing in gridview.
and if following sql is used-
"select cust.*,brok.FirstName+' '+brok.LastName as Name,
from custmsgrecieved as cust,brokerdetails as brok
where cust.CustId='1001' or brok.BrokerId=cust.FromBrokerId"
then that row is appeared no. of times equal to no. of rows in brokerdetails.
I want that in gridview row correspondimg to FromBrokerId=NULL in custmsgrecieved appears as it is that is appear one time and also that column of gridview binded with "Name" has text "administrator".
plz help me...
|
|
|
|
|
I'm not sure if I follow what you're saying or asking, but I believe you want to use a JOIN statement in your SQL
SELECT ...
FROM Table1
JOIN Table2 on Table2.field = Table1.field
only two letters away from being an asset
|
|
|
|
|
Want to do clienside validation on a textbox control. This textbox can represent two data types depending on an associtate checkbox. So if checkbox is checked the validation should do (a) and if off do (b)
In the javascript funtion below I do a getElementForID("chkBox1")
However if I want this to be a global routine I don't know what the checkBox would be
and preferably I'd like to pass an Integer so I could do multiple validations on this control or others. The "Sender" parameter seems to be my textbox, So question is how do I setup the ClientValidationFuntion property of the validator to pass an integer?
My custom validator is setup like this
<asp:CustomValidator ID="lsdCustomVal" ControlToValidate="txtBox1" runat="server"
ClientValidationFunction= "validateLSDControl"></asp:CustomValidator>
in my external js file I have >>
function validateLSDControl( sender, args)
{
var expr1 = "[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]";
var expr2 = "[a-z]-[0-9][0-9][0-9]-[A-Z]/[0-9][0-9]";
var x = document.getElementById(sender.controltovalidate);
var chkbox = document.getElementById("chkBox1");
var smsg = "";
if (chkbox.checked) {
var patt1 = new RegExp(expr, "g");
smsg = "expr1 Invalid";
}
else {
var patt1 = new RegExp(nts, "g");
smsg = "expr2 Invalid";
}
var result = false;
if (x != null) {
var s = x.value;
if (s.match(patt1))
{
// alert("it worked");
result = true;
}
else
alert(smsg);
}
args.isValid = result;
}
|
|
|
|
|
if you are using masterpage then you must below code to access asp control
like
document.getElementById('<%= chkBox1.ClientID%>');
or
change the form's default name according you and access the control by
FORMNAME.GETELEMENTBYID
plz check it.
Rajeev Kr. Sharma
Sr. Software Engineer
E-Meditek Solutions Ltd.
http://www.emeditek.co.in/
|
|
|
|
|
Below is my databse table..
I can populate this data into the UI Page..
My task is to automatically delete the columns which has '0'(zero) value...and i have to delete the first row of my table...
Hear i am not going to use any itemtemplate column..
I have to write some code in codebehind..
JurisdictionID JurisdictionDescription Year1 Year2 Year3 Year4 Year5 Year6 Year7
2005 2006 2009 0 0 0 0
AL Alabama 0 0 6 0 0 0 0
AK Alaska 2 0 0 0 0 0 0
Could Anyone suggest me ..How to proceed further in detail with some code...
modified on Monday, June 1, 2009 4:24 PM
|
|
|
|
|
foreach (GridViewRow Row in grd.Rows)
{
for (int i = 0; i<7; i++)
{
if (Row[i].ToString().Equals("0"))
{
grd.Columns.Remove(Row[i]);
}
}
}
I have not tested this code. Let me know if it works or not so as to fix the errors. Regards
|
|
|
|
|
hey..i am getting some errors..when am using that code..
in which method we have to write tht code..
i wrote in...
public void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
i am getting errors like this..
1) 'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level
2) Cannot apply indexing with [] to an expression of 'System.Web.UI.WebControls.GridViewRow'
actually am poor in c# technologies..could you sen dme solution fot this..
|
|
|
|
|
Sorry, I was closing from work when I posted. This should work:
foreach (GridViewRow Row in GridView1.Rows)
{
for(int i=0; i < 7; i++)
{
if (Row.Cells[i].Text == "0")
{
GridView1.Columns.Remove(GridView1.Columns[i]);
}
}
}
I called up this function from a button which I created. You can place it within the GridView1_RowDeleting if you wish without problems.
As per deleting first row, I suggest deleting it from database first (using sql query) and re-binding your gridview.
|
|
|
|
|
hey..thnx for ur reply..
i am writting the code in the row delete event only...
i am not getting any errors..when i execute this code...somehow am unable to delete the columns....
is there any pother way to do..?
|
|
|
|
|
If what you want to do is to delete a column from the underlying database table I'm not sure I can help you on that.
If what you want h/ever is to simply hide the column from the GridView this should work otherwise you can replace GridView1.Columns.Remove(GridView1.Columns[i]); with GridView1.Column[i].Visible = false;
I've tested the previous code and it worked.
Why not post more code for us to see where you're getting it wrong?
|
|
|
|
|
by using above syntax also..i can't see anychange in the table..i can see all the columns..the 0(zero) value cell columns are not hiding..
actullt my task is to delete those columns..am unable to do that..
atleast i want to try with hiding those columns..
below i copied my code of populating data into gridview and the rowdelete event..
protected void Page_Load(object sender, EventArgs e)
{
PopulateGrid();
}
public void PopulateGrid()
{
SqlConnection sqlConn = null;
SqlDataAdapter da = null;
try
{
string connString = null;
SqlCommand cmd1;
connString = System.Web.Configuration.WebConfigurationManager.AppSettings["SqlServerConnectionString"];
sqlConn = new SqlConnection(connString);
sqlConn.Open();
cmd1 = new SqlCommand("[MED].[usp_SelectAllSDNCounts]", sqlConn);
cmd1.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
finally
{
sqlConn.Close();
da.Dispose();
da = null;
}
}
public void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
foreach (GridViewRow Row in GridView1.Rows)
{
for(int i=0; i<11; i++)
{
if (Row.Cells[i].Text == "0")
{
GridView1.Columns[i].Visible=false;
}
}
}
}
|
|
|
|
|
Change:
protected void Page_Load(object sender, EventArgs e)
{ PopulateGrid();
}
to:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
PopulateGrid();
}
}
Does this help? 
|
|
|
|