|
public partial class _Default : System.Web.UI.Page
{
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
grd_bind();
}
private void grd_bind()
{
SqlDataAdapter adp = new SqlDataAdapter("select * from tbdep; select * from tbemp7", ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
adp.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
public DataSet getdata(Int32 dno)// public because we access it in HTML
{
string qry = "select * from tbemp7 where edno=" + dno.ToString();// we can't use it as performance low as it execute much a times
DataView dv;//to sort data, to filter data, to navigate data on dataset we use it
dv = ds.Tables[1].DefaultView;
dv.RowFilter = "edno=" + dno.ToString();
return dv;
}
}
IN HTML :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="778px" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"
Height="281px">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:TemplateField HeaderText="department">
<ItemTemplate>
<b>
dep no:</b><%#Eval("dno") %><br />
<b>dep name:</b><%#Eval("dname") %></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="emp detail">
<ItemTemplate>
<asp:GridView ID="Gridview1" DataSource='<%#getdata(Convert.ToInt32(Eval("dno"))) %>' AutoGenerateColumns="false" Width="100px" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="EMPNO" DataField="empno" />
<asp:BoundField HeaderText="NAME" DataField="ename" />
<asp:BoundField HeaderText="ADDRESS" DataField="eadd" />
<asp:BoundField HeaderText="SALARY" DataField="esal" />
</Columns>
|
|
|
|
|
That's pretty bad programming:
1. You populate a dataset and assign it to grid in code behind file without IsPostback condition leading to data load on every postback
2. You again populate a dataset, use dataview to filter and assign again to another grid with same ID as previous one in aspx
3. You use wrong table index while assigning it to dataview.
4. You assign a number to datasource of inner grid instead of a view!
Try:
1. Make sure you have different names of the grids.
2. While fetching a table from database, only one table is returned for a select statement, so you use ds.Tables[0]
3. Look at this article on how to use Nested Grid:
MSDN: Walkthrough: Creating a Nested GridView Control[^]
Editable Nested GridView (All-in-One)[^]
|
|
|
|
|
I'm using a FormView that is bound to an ObjectDataSource. My ObjectDataSource is bound to a Linq2Sql table object. Update and delete are working fine. I'm having problems with insert. When I try and insert the DataItem that the FormView is bound to is null. How do I set the DataItem to a new entity object?
|
|
|
|
|
i tried to load pages from database and make numbers down the page loader but it does not work and it change the style of masterbage right side of master page show down the page loader
|
|
|
|
|
Your question makes no sense: try to rephrase or get someone who speaks English to translate or you won't get an answer.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Based on the words used in your question, you have page-design issue. You need to share the related code to get some insight.
Surely English is not your first language. Please get someone who can write/frame a proper question for you such that you can get some help. For now, it's difficult to make much out of what you ask.
|
|
|
|
|
hello.
I have design a form with asp.net4 which is binded to Sqlserver 2008r2 , my form is made by Asp.Net formview that has to insert data into the database . i have also included my formview inside an UpdatePanel , but when press the insert button this exception in the is generated:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.
this exception occures in a locked dynamic page: ScriptResource.axd
but whenever i remove the UpdatePanel from my form this exception doesn't occure again , but the other Unhandled exception occures :
(in fact i don't want to remove UpdatePanel)
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
<div style="display: block;" id="premain0" class="pre-action-link" width="100%">[FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9591147 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119 System.String.System.IConvertible.ToInt32(IFormatProvider provider) +46 System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +297 System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +126 System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +63 System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +550 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +306 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +89 System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +377 System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +612 System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +112 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +125 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +167 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563</div>
someone said to me i should convert string datatype to int, but i don't know how & where should i modify the code ?
|
|
|
|
|
It's seems something issue with Data conversion. So check carefully for all data types wherever converting any input data.
One more thing:
Try to set the page attribute :
EnableEventValidation="false"
Parwej Ahamad
|
|
|
|
|
Hi,
As per my understanding, its a data convertion issue, its trying to convert from a string to int.
you can try below:
CAST(MyVarcharCol AS INT))
or
CONVERT(INT, MyVarcharCol)
|
|
|
|
|
You'll need to see what the actual value is. Step through with a debugger and/or add a try/catch to log the value somewhere.
|
|
|
|
|
I have a C# 201o web form application that I just deployed to a test server that is similar to the production server running iis 7. The entire website works fine but the screens only stay active for an inconsistent amount of time. The entire website throws you back to the main logon screen. Thus can you tell me what kind of a setting for the entire web site and/or iis server that needs to be changed so the server and /or application does not throw you out to the logon page after being on the website for 5 minutes or less?
|
|
|
|
|
|
This article says the default timeout for asp.net is 20 minutes. However, my website closes down after 3 to 5 minutes at the most.
Thus do you think something else could be wrong? Do I just need to set the session timeout value since I do not have the value set?
|
|
|
|
|
Verify Web.Config file, what the time is set for Form authentication tag?
Parwej Ahamad
|
|
|
|
|
dcof wrote: website throws you back to the main logon screen
This is like the 3rd time I read the question.
I didn't think much at first of the question because it did sound like a session issue.
So do you mean that if you navigate to a page, and sit in your chair and watch it, the page automatically navigates to the login screen?,
or if you get a phone call, and your talking on the phone, the page redirects?
dcof wrote: <layer>but the screens only stay active for an inconsistent amount of time.
Is the incosistent time always on the same computer?, or various computers.
|
|
|
|
|
Do you have an example with asp:Panel to look like tab control?
|
|
|
|
|
Tab control for ASP.NET Applications[^].
Good place to start: there are a few other similar articles.
There's also Google[^]
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
|
hello friends i am fresher i need real time example for using oops in asp.net with C# application..give me some code..
|
|
|
|
|
|
Start with some good samples on msdn.
You can also pick up a good book and read.
|
|
|
|
|
|
|
Try DotnetFunda, Questpond. The second one requires a payment for their training and dvd's. But the amount is very nominal and worth it.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
You can for example enter the length and width of the web (VS.NET2005), when it runs out of range index error exception was unhandled by user code for chieudai
public class Tinh
{
private Int32 _quanhuyen;
private String _diachiNha;
private Double _chieudai;
private Double _chieurong;
private Double _dientichDat;
}
public Int32 Quanhuyen
{
get { return _quanhuyen; }
set { _quanhuyen = value; }
}
public String DiachiNha
{
get { return _diachiNha; }
set { _diachiNha = value; }
}
public Double Chieudai
{
get { return _chieudai; }
set { _chieudai = value; }
}
public Double Chieurong
{
get { return _chieurong; }
set { _chieurong = value; }
}
public Double DientichDat
{
get { return _dientichDat; }
set { _dientichDat = value; }
}
private Tinh DienTich(IDataReader dr, bool GetTotalRecords)
{
Tinh obj = new Tinh();
...
obj.Quanhuyen = (dr["Quanhuyen"] is DBNull) ? Int32.MinValue : (Int32)dr["Quanhuyen"];
obj.DiachiNha = (dr["DiachiNha"] is DBNull) ? String.Empty : (String)dr["DiachiNha"];
// bottom line this error index out of range exception was unhandled by user code
obj.Chieudai = (dr["Chieudai"] is DBNull) ? Double.MinValue : (Double)dr["Chieudai"];
obj.Chieurong = (dr["Chieurong"] is DBNull) ? Double.MinValue : (Double)dr["Chieurong"];
obj.DientichDat = (dr["DientichDat"] is DBNull) ? Double.MinValue : (Double)dr["DientichDat"];
if (GetTotalRecords)
obj.TotalRecords = (dr["TotalRecords"] is DBNull) ? -1 : Globals.ConvertToInt32(dr["TotalRecords"]);
return obj;
}
error index out of range exception was unhandled by user code
modified 11-Jul-12 3:04am.
|
|
|
|