|
thanks for the replay SABhatti
u r right its loosing information on every post i did refered the example u told bt same is happening over here can u give me some example in coding form a very simple example one button and textbox when u click button textbox shud b added every time u click the button new textbox shud b added
any help will be greatly appreciated
thanks in advance
|
|
|
|
|
Well ShaikhAffi, I have not tried anything like this but quickly I can give you one idea (there are definitely other ways too but right now I can give you this which will definitely work).
keep a hidden field or session variable, every time user clicks the button increase that field by 1 (on the server side not on the client) now in page load do this:
<br />
if(!IsPostBack)<br />
preserveControls()<br />
<br />
protected void preserveControls()<br />
{<br />
int noOfControls = (hiddenfield.Value.Length > 0) ? (int)hiddenfield.Value : 0;<br />
if(noOfControls > 0)<br />
for(int i=0; i < noOfControls; i++)<br />
{
}<br />
<br />
and in button ClickEvent add the control and increment the hiddenfieldValue by 1
-----
|
|
|
|
|
Well Thank u very much for ur reply bt i this solution wont b suitable for my prob coz in each row i have atleast 5 textboxes so it will make the problem complecated what do u think
|
|
|
|
|
here is the sample page for exactly what you want:
aspx page (I have added only one template column with text box, but you can add as many as you want):
<asp:GridView ID="gv" runat="server" OnRowDataBound="gvRowDataBound">
<Columns>
<asp:TemplateField HeaderText="test">
<ItemTemplate>
<asp:TextBox ID="tb" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btn" runat="server" Text="Add" OnClientClick="javascript:document.getElementById('hf').value='true';return true;" />
<asp:HiddenField ID="hf" runat="server" />
code behind file:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Request.Form["hf"] == "true")
addGVRow();
hf.Value = string.Empty;
}
private void addGVRow()
{
DataTable dt = (DataTable)Session["dt"];
int counter = 0;
if (dt == null)
{
dt = new DataTable();
dt.Columns.Add("seq");
}
else
counter = dt.Rows.Count;
DataRow dr = dt.NewRow();
dr[0] = counter + 1;
dt.Rows.Add(dr);
gv.DataSource = dt;
gv.DataBind();
Session["dt"] = dt;
}
protected void gvRowDataBound(object sender, GridViewRowEventArgs e)
{
// hide the last cell (sequence)
e.Row.Cells[e.Row.Cells.Count - 1].Visible = false;
}
I am assuming that first time the page will be blank with add button only.
-----
|
|
|
|
|
Actual SA Bhati i need to add row in table server control not in datagrid
i nedd to add row in existing table the row shud contain atleas 4 to 5 textboxes
hope u understood
well thank u very much for the help
|
|
|
|
|
tell me briefly what your are trying to achieve? I mean what is the resulting output for the user? and and what you want from the user?
-----
|
|
|
|
|
well im working on an application for my father's buisness he has whole sale shop so whn a customer comes he may purchase items obviously he can purchase more than one time so im developing cash memo in tht cash memo ther are four textboxes for the itemName quantity saleprice and total and there is one button name addMoreItem so wht i want when user clicks this button same row of four textboxes shud b added every time user clicks row with the textboxes shud be added.after submitting the form whole data has to be saved in database the problem as i already told u is im unable to dynamically add row in table. hope u understand
|
|
|
|
|
well the solution/sample page I gave you for gridview does exactly the same thing and I'll suggest to use gridview instead of table server control. But, if you want to use table control then you can try the same logic for that.
-----
|
|
|
|
|
well SA Bhatti i tried ur code the prob is u have implemented the session table tht i dont want coz if u will use session table then probably when u come back to tht page it will insert the last no: of rows
|
|
|
|
|
on page load i just equals the session table to null now the problem is solved bt how can i access the each textbox in grid view well thank u very much
i w8 for ur reply
|
|
|
|
|
In aspx page add save button like:
<br />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /><br />
<br />
in code behind file do this:
<br />
protected void btnSave_Click(object sender, System.EventArgs e)<br />
{<br />
foreach (GridViewRow row in gv.Rows) <br />
{<br />
TextBox tb = (TextBox)row.FindControl("tb");<br />
string valueTyped = tb.Text;<br />
}<br />
}<br />
-----
|
|
|
|
|
thank u very much
and wht if i want to display serial no as well and i can delete the row.
i want delete button on each row so whenever i press it that row shud be deleted well i can add delete button but i dont know the logic
any help will be greatly appreciated.
thank
|
|
|
|
|
Salams
ur code is giving problem when im using in page tht is using a master page
sometimes it gives this error
ystem.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 28:
Line 29:
Line 30: hf.Value = string.Empty;
Line 31:
Line 32:
Source File: f:\erpSite\erp2\test.aspx.cs Line: 30
and onother time it gives this error
System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 47: dr[0] = counter + 1;
Line 48: dt.Rows.Add(dr);
Line 49: gv.DataSource = dt;
Line 50: gv.DataBind();
Line 51: Session["dt"] = dt;
Source File: f:\erpSite\erp2\test.aspx.cs Line: 49
|
|
|
|
|
well, its not my code instead it is your logic that giving you the error. It seems that you are accessing the hidden field (hf) and gridview (gv) in test.aspx.cs but hf and gv are not declared in test.aspx. So check if you have declared them in this page. You should check you test.aspx page and then run in debug mode and see the cause of error.
To show the sequence number on the page comment the code in rowdatabound that has row.cells[row.cells.count-1].visible = false. For deleting a row set allowdelete (you can check actual syntax in visual studio) to true and then in RowCommand delete that row from the gridview and from the datatable in session. (you can find the row based on the sequence number and delete it from the session).
-----
|
|
|
|
|
i have checked hf and gv already exist in the page it gives the same error i told u wht shud i do
|
|
|
|
|
the second problem is as i told u i have a textbox named item there is a button besides tht textbox on each row when i click tht button a pop up shud be open well i opened the pop through the javascript now i want to pass the client id of tht textbox i mean item to tht javascript function which is calling the pop.so plz help me out this problem is driving me crazy
any help wud greatly be appreciated
i will wait for ur reply
u have solved my prob until now this is the last problem plz do me favour
thank u very much
|
|
|
|
|
please help me out
well i done all these things by my self now the only problem remains is when i reload or refresh my page automatically row is inserted i dont want this please reply
|
|
|
|
|
hi , i have an idea i wish to do it
i have a listbox it's disply member is StudentName and value member is StudentCode
i want to write the student name in textbox and find this name in listbox by like
examble i search for name Mohammed and i write in textbox Mo how can i select the first item match this
thnx 4 help
MD_NADA
|
|
|
|
|
Loop though the elements in the list.
Call the String.StartsWith method on the display member for each element with the value entered in the listbox. If this method returns True for a particular item, the item begins with the text entered in the textbox.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hello everyone,
I am trying to debug a Class Library. My question is:
Once the Class Library project is built and attached to a running process; using Module Windows, should I be able to see that MyProject.DLL file has been loaded?
Any information on attaching and debuging a Class Library project to a running process will greatly be appriciated.
Thank you very much and have a great day.
Khoramdin
-- modified at 12:18 Sunday 18th November, 2007
|
|
|
|
|
You would normally have your class library project in the same solution as the other projects you are working on. The debgging is seamless and flows through from one project to another.
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
Hello Colin,
Thanx for the reply. You are absolutly correct if the Class Library was created for an exsisting project. I am not able to do so since the Class Library is for creating a Browser Helper Object (BHO). That is why I am using Attach Process to attach it to IE Browser.
I am trying to undrestand the way Class Library works in Visual Studio, so I can solve the issue I am currently facing.
Thank you for taking the time and respond. Any information in regard with this is greatdly appriciated, Colin.
Have a great weekend.
Khoramdin
|
|
|
|
|
hi all,
i have problem that i m unable to use ExecuteNonQuery() and "EXISTS" of sql
i want to check in my table that the required row is exists or not
i used ExecuteNonQuery() but it always returns -1
codes
dataCommand.CommandText = "select * from tabel1 where id = '" + label1.Text + "'";
int check = dataCommand.ExecuteNonQuery();
if (check > 0)
{
MessageBox.Show("this is already exists");
return;
}
for temporary i m using SQLDataReader's HasRows bool
can someone have another best solution?
Becoming Programmer...
|
|
|
|
|
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT COUNT(*) FROM table1 WHERE id = @id";
cmd.Parameters.AddWithValue("@id", label1.Text);
cmd.Connection = myConnection;
int count = cmd.ExecuteScalar();
if (count > 0)
{
}
Please also note that the above uses a parameterised query thus reducing the posibility of a SQL Injection attack. You may also like to read SQL Injection Attacks and Tips on How To Prevent Them[^]
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
yeah it will work but why microsoft made "EXISTS" function in sql ...??
Becoming Programmer...
|
|
|
|