Thursday, March 29, 2012
Please explain why AddHandler works in Page_Load, but not Butt
that would look a bit like google. State 1, you see a textbox and button, yo
u
type a search value and press the button, State 2, a list of search results
is displayed (a table with a LinkButton in each row), you click on the
selected row's LinkButton. State 3, The details about the selected item are
displayed along with a button to go back to state 1.
The database search after state 1 and the insertion of the results and
LinkButtons in the table must take place in the Button's Click event, the
table duly appears with the data and LinkButtons. At the end of state 2, the
LinkButtons cause a post, but no event is fired, also the entire contents of
the table no longer exist - this does not matter as I only want to know the
ID of the button.
Is the idea of linking the dynamically created LinkButtons to an event the
wrong approach? Should I be looking at the request.form(0) value? Or is my
whole approach wrong, am I thinking too much along Windows Forms lines?
--
John Austin
"Cowboy (Gregory A. Beamer)" wrote:
> It has to do with the order of events in .NET. By the time you hit button
> events, you have already configured controls. Under "sender", you can find
> out which button was clicked and adjust appropriately in Page_Load. Be
> careful, however, with overloading Page_Load with too much, as you can end
> up with disaster.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com
> ****************************************
*********
> Think outside of the box!
> ****************************************
*********
> "John Austin" <John.Austin@dotnet.itags.org.nospam.nospam> wrote in message
> news:08B9C89B-CB28-41CE-899E-4AF85F704B84@dotnet.itags.org.microsoft.com...
>
>Hi John,
First, I recommend you to use [1] as your starting point to learn ASP.NET.
Though it's written for ASP.NET 1.x, it should get you started.
Since ASP.NET page is stateless, a page class instance and its controls
will need to be created at the server side every time the page is posted
back. See following steps to get an overview of the page life cycle:
1) POST Request is issued by client
2) Page-derived class is created, constructor is invoked
3) IHttpHandler.ProcessRequest is invoked (implemented by Page)
4) Page.Init()
5) Page.CreateChildControls()
6) Server-side control state is restored from POST variables and VIEWSTATE
7) Page.Load()
8) Page.Validate()
9) Server-side control events are fired
10) Page.PreRender()
11) Page.Render()
12) Page.RenderChildren()
13) HTTP Response is issued to client
14) Page.Unload()
15) Instance of Page-derived class is discarded
Each control will have a unique ID, this ID will be used to restore the
state from POST variables and VIEWSTATE (step 6) to the re-created controls
(step 5).
During load (step 7), if the current request is a postback, control
properties are loaded with information recovered from view state and
control state. (See [2] fore more information)
For your dynamically added controls to restore state correctly, you must
make sure the controls are added before the Load event. It's a best
practice to re-create them in Page.Load.
Regarding your issue, the LinkButtons are created in Button's Click event,
they are displayed in the result for the first time since Render is taken
place after that (step 11 and step 9). When the LinkButton is clicked and
caused a postback, the LinkButtons are not re-created, and the POST
variables related to them are lost. You could check the Request.Form for
the field that caused the postback, but there're better way to fulfil your
requirement.
Actually your requirement can be best handled by the Repeater [3] control
and DataBinding:
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
<br />
<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="link1" runat="server" CommandName="Link1"
CommandArgument='<%# Eval("Description") %>' Text='<%# Eval("Name") %>'
></asp:LinkButton>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Description");
dt.Rows.Add("First", "This is the first item");
dt.Rows.Add("Second", "This is the second item");
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "Link1")
{
Response.Write(e.CommandArgument);
}
}
LinkButton's Click event will be bubbled up to the Repeater and fire
ItemCommand instead. Using the CommandName and CommandArgument, we can
differentiate which LinkButton is clicked.
I hope this could help you get familiar with how ASP.NET works and how to
handle such scenario using appropriate controls. Please feel free to let me
know whether or not you need further information. Thank you.
References:
[1] INFO: ASP.NET Roadmap
http://support.microsoft.com/kb/305140/
[2] ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx
[3] Repeater Web Server Control Overview
http://msdn2.microsoft.com/en-us/library/x8f2zez5.aspx
Sincerely,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...t/default.aspx.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Thank you Walter for your excellent reply. Whilst checking request.form(0) i
n
Page_Load was a work around (after they click, I don't want the table
anyway), the Repeater is a better solution for me as I can use the event
driven methodology that I am used to with Windows Forms applications.
Thanks once again,
--
John Austin
"Walter Wang [MSFT]" wrote:
> Hi John,
> First, I recommend you to use [1] as your starting point to learn ASP.NET.
> Though it's written for ASP.NET 1.x, it should get you started.
> Since ASP.NET page is stateless, a page class instance and its controls
> will need to be created at the server side every time the page is posted
> back. See following steps to get an overview of the page life cycle:
> 1) POST Request is issued by client
> 2) Page-derived class is created, constructor is invoked
> 3) IHttpHandler.ProcessRequest is invoked (implemented by Page)
> 4) Page.Init()
> 5) Page.CreateChildControls()
> 6) Server-side control state is restored from POST variables and VIEWSTATE
> 7) Page.Load()
> 8) Page.Validate()
> 9) Server-side control events are fired
> 10) Page.PreRender()
> 11) Page.Render()
> 12) Page.RenderChildren()
> 13) HTTP Response is issued to client
> 14) Page.Unload()
> 15) Instance of Page-derived class is discarded
> Each control will have a unique ID, this ID will be used to restore the
> state from POST variables and VIEWSTATE (step 6) to the re-created control
s
> (step 5).
> During load (step 7), if the current request is a postback, control
> properties are loaded with information recovered from view state and
> control state. (See [2] fore more information)
> For your dynamically added controls to restore state correctly, you must
> make sure the controls are added before the Load event. It's a best
> practice to re-create them in Page.Load.
> Regarding your issue, the LinkButtons are created in Button's Click event,
> they are displayed in the result for the first time since Render is taken
> place after that (step 11 and step 9). When the LinkButton is clicked and
> caused a postback, the LinkButtons are not re-created, and the POST
> variables related to them are lost. You could check the Request.Form for
> the field that caused the postback, but there're better way to fulfil your
> requirement.
> Actually your requirement can be best handled by the Repeater [3] control
> and DataBinding:
>
> <asp:Button ID="Button1" runat="server" Text="Button"
> OnClick="Button1_Click" />
> <br />
> <asp:Repeater ID="Repeater1" runat="server"
> OnItemCommand="Repeater1_ItemCommand">
> <HeaderTemplate>
> <ul>
> </HeaderTemplate>
> <ItemTemplate>
> <li>
> <asp:LinkButton ID="link1" runat="server" CommandName="Link1"
> CommandArgument='<%# Eval("Description") %>' Text='<%# Eval("Name") %>'
> </li>
> </ItemTemplate>
> <FooterTemplate>
> </ul>
> </FooterTemplate>
> </asp:Repeater>
>
> protected void Button1_Click(object sender, EventArgs e)
> {
> DataTable dt = new DataTable();
> dt.Columns.Add("Name");
> dt.Columns.Add("Description");
> dt.Rows.Add("First", "This is the first item");
> dt.Rows.Add("Second", "This is the second item");
> Repeater1.DataSource = dt;
> Repeater1.DataBind();
> }
> protected void Repeater1_ItemCommand(object source,
> RepeaterCommandEventArgs e)
> {
> if (e.CommandName == "Link1")
> {
> Response.Write(e.CommandArgument);
> }
> }
> LinkButton's Click event will be bubbled up to the Repeater and fire
> ItemCommand instead. Using the CommandName and CommandArgument, we can
> differentiate which LinkButton is clicked.
> I hope this could help you get familiar with how ASP.NET works and how to
> handle such scenario using appropriate controls. Please feel free to let m
e
> know whether or not you need further information. Thank you.
> References:
> [1] INFO: ASP.NET Roadmap
> http://support.microsoft.com/kb/305140/
> [2] ASP.NET Page Life Cycle Overview
> http://msdn2.microsoft.com/en-us/library/ms178472.aspx
> [3] Repeater Web Server Control Overview
> http://msdn2.microsoft.com/en-us/library/x8f2zez5.aspx
> Sincerely,
> Walter Wang (wawang@.online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
> ========================================
==========
> Get notification to my posts through email? Please refer to
> [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/ur
l]
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your repl
y
> promptly.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscript...t/default.aspx.
> ========================================
==========
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Hello Walter,
The Data Repeater works fine, but thinking further about the issue, it would
make sense for state 1 to build a query string from input criteria and store
the select statement in viewstate so that the Page_Load in state 2 can query
the database and generate results (this means that pressing Back in the
browser from state 3 would re-query the database and include any changes).
This would also avoid my original problem; but when in state 1, the button
press would need to build the query string, change the state to 2 and then
force a reload of the current page. How could I force the page to be re-buil
d
from the Button_Click event?
John Austin
"Walter Wang [MSFT]" wrote:
> Hi John,
> First, I recommend you to use [1] as your starting point to learn ASP.NET.
> Though it's written for ASP.NET 1.x, it should get you started.
> Since ASP.NET page is stateless, a page class instance and its controls
> will need to be created at the server side every time the page is posted
> back. See following steps to get an overview of the page life cycle:
> 1) POST Request is issued by client
> 2) Page-derived class is created, constructor is invoked
> 3) IHttpHandler.ProcessRequest is invoked (implemented by Page)
> 4) Page.Init()
> 5) Page.CreateChildControls()
> 6) Server-side control state is restored from POST variables and VIEWSTATE
> 7) Page.Load()
> 8) Page.Validate()
> 9) Server-side control events are fired
> 10) Page.PreRender()
> 11) Page.Render()
> 12) Page.RenderChildren()
> 13) HTTP Response is issued to client
> 14) Page.Unload()
> 15) Instance of Page-derived class is discarded
> Each control will have a unique ID, this ID will be used to restore the
> state from POST variables and VIEWSTATE (step 6) to the re-created control
s
> (step 5).
> During load (step 7), if the current request is a postback, control
> properties are loaded with information recovered from view state and
> control state. (See [2] fore more information)
> For your dynamically added controls to restore state correctly, you must
> make sure the controls are added before the Load event. It's a best
> practice to re-create them in Page.Load.
> Regarding your issue, the LinkButtons are created in Button's Click event,
> they are displayed in the result for the first time since Render is taken
> place after that (step 11 and step 9). When the LinkButton is clicked and
> caused a postback, the LinkButtons are not re-created, and the POST
> variables related to them are lost. You could check the Request.Form for
> the field that caused the postback, but there're better way to fulfil your
> requirement.
> Actually your requirement can be best handled by the Repeater [3] control
> and DataBinding:
>
> <asp:Button ID="Button1" runat="server" Text="Button"
> OnClick="Button1_Click" />
> <br />
> <asp:Repeater ID="Repeater1" runat="server"
> OnItemCommand="Repeater1_ItemCommand">
> <HeaderTemplate>
> <ul>
> </HeaderTemplate>
> <ItemTemplate>
> <li>
> <asp:LinkButton ID="link1" runat="server" CommandName="Link1"
> CommandArgument='<%# Eval("Description") %>' Text='<%# Eval("Name") %>'
> </li>
> </ItemTemplate>
> <FooterTemplate>
> </ul>
> </FooterTemplate>
> </asp:Repeater>
>
> protected void Button1_Click(object sender, EventArgs e)
> {
> DataTable dt = new DataTable();
> dt.Columns.Add("Name");
> dt.Columns.Add("Description");
> dt.Rows.Add("First", "This is the first item");
> dt.Rows.Add("Second", "This is the second item");
> Repeater1.DataSource = dt;
> Repeater1.DataBind();
> }
> protected void Repeater1_ItemCommand(object source,
> RepeaterCommandEventArgs e)
> {
> if (e.CommandName == "Link1")
> {
> Response.Write(e.CommandArgument);
> }
> }
> LinkButton's Click event will be bubbled up to the Repeater and fire
> ItemCommand instead. Using the CommandName and CommandArgument, we can
> differentiate which LinkButton is clicked.
> I hope this could help you get familiar with how ASP.NET works and how to
> handle such scenario using appropriate controls. Please feel free to let m
e
> know whether or not you need further information. Thank you.
> References:
> [1] INFO: ASP.NET Roadmap
> http://support.microsoft.com/kb/305140/
> [2] ASP.NET Page Life Cycle Overview
> http://msdn2.microsoft.com/en-us/library/ms178472.aspx
> [3] Repeater Web Server Control Overview
> http://msdn2.microsoft.com/en-us/library/x8f2zez5.aspx
> Sincerely,
> Walter Wang (wawang@.online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
> ========================================
==========
> Get notification to my posts through email? Please refer to
> [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/ur
l]
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your repl
y
> promptly.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscript...t/default.aspx.
> ========================================
==========
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Hi John,
See if following code answers your question:
protected void Page_Load(object sender, EventArgs e)
{
RebindData();
}
protected void Button1_Click(object sender, EventArgs e)
{
QueryStatement = "foo sql statement";
RebindData();
}
void RebindData()
{
string sql = QueryStatement;
if (string.IsNullOrEmpty(sql))
{
Repeater1.DataSource = null;
}
else
{
// you need to do sql query in real app; here I'm just
returning a DataTable for test purpose
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Description");
dt.Rows.Add("First", "This is the first item");
dt.Rows.Add("Second", "This is the second item");
Repeater1.DataSource = dt;
}
Repeater1.DataBind();
}
string QueryStatement
{
get { reutrn ViewState["QueryStatement"] as string; }
set { ViewState["QueryStatement"] = value; }
}
protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == "Link1")
{
Response.Write(e.CommandArgument);
}
}
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Sorry Walter, putting the creation of the results table in a subroutine is a
far simpler solution - I guess that getting my head round the way web app
work clouded the brain!
Many thanks,
John Austin
"Walter Wang [MSFT]" wrote:
> Hi John,
> See if following code answers your question:
> protected void Page_Load(object sender, EventArgs e)
> {
> RebindData();
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> QueryStatement = "foo sql statement";
> RebindData();
> }
> void RebindData()
> {
> string sql = QueryStatement;
> if (string.IsNullOrEmpty(sql))
> {
> Repeater1.DataSource = null;
> }
> else
> {
> // you need to do sql query in real app; here I'm just
> returning a DataTable for test purpose
> DataTable dt = new DataTable();
> dt.Columns.Add("Name");
> dt.Columns.Add("Description");
> dt.Rows.Add("First", "This is the first item");
> dt.Rows.Add("Second", "This is the second item");
> Repeater1.DataSource = dt;
> }
> Repeater1.DataBind();
> }
> string QueryStatement
> {
> get { reutrn ViewState["QueryStatement"] as string; }
> set { ViewState["QueryStatement"] = value; }
> }
> protected void Repeater1_ItemCommand(object source,
> RepeaterCommandEventArgs e)
> {
> if (e.CommandName == "Link1")
> {
> Response.Write(e.CommandArgument);
> }
> }
> Regards,
> Walter Wang (wawang@.online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
> ========================================
==========
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
==========
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Saturday, March 24, 2012
PLEASE HELP = odd TextChanged behavior
TextChanged event is fired. The page should reload and display a new value
in another textbox. Both are WebControls.
The first Textbox performs the appropriate action.
The SECOND does not fire TextChanged until AFTER I click the Submit button.
It does not fire when I change the text and lose the control focus. Both
code blocks for the event handlers are IDENTICAL.
Anyone know why?Just to make sure:
have you set the autopostback flag to true?
Seb.
Just to make sure:
have you set the autopostback flag to true?
Seb.
heh... *sheepish grin*
"Seb" <anonymous@.discussions.microsoft.com> wrote in message
news:073501c39869$48c82490$a501280a@.phx.gbl...
> Just to make sure:
> have you set the autopostback flag to true?
> Seb.
heh... *sheepish grin*
"Seb" <anonymous@.discussions.microsoft.com> wrote in message
news:073501c39869$48c82490$a501280a@.phx.gbl...
> Just to make sure:
> have you set the autopostback flag to true?
> Seb.
Please help Friends how to control maxlength textbox in datagrid
My database table field size is only 10 chars for first name.
How can i make the user not to enter more tha 10 chars on the front end.
Is there any Max length property i can assign for the text boxes.
I have 4 text boxes in datagrid.
Thank you very much.Hi,
if it is single-line TextBox, you can use its MaxLength property like you normally can.
<asp:TextBox ID="xxx" MaxLength="4"... /
This works even if TextBox is in a DataGrid.
Thanks Joteke, I have the following code triggered when i click edit in the datagrid, then it will show all text boxes etc. where can i place the maxlength="4" property in the following code.
Thank you very much.
< Code >
Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim strConn as string = "server=Rajender;uid=sa;pwd=sa;database=NORTHWIND"
Dim txtFirstName As textbox = E.Item.cells(2).Controls(0)
Dim txtLastName As textbox = E.Item.cells(3).Controls(0)
Dim txtTitle As textbox = E.Item.cells(4).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt =" UPDATE Employees SET" & _
" FirstName =@.Fname, LastName =@.Lname, Title = @.Title " & _
" WHERE EmployeeID = @.EmpID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SQLParameter("@.Fname", txtFirstName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Lname", txtLastName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Title", txtTitle.text))
MyCommand.Parameters.Add(New SQLParameter("@.EmpID", e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub
</ code >
In that case, you could declare EditItemTemplate for the DataGrid (declaratively in asox) in which you set the TextBox's MaxLength.
If you want to do it programmatically, then you'd do it in ItemDataBound method (when ItemType is EditItem)
Wednesday, March 21, 2012
please help i need help urgently
Hi
I am working on asp.net application using vb.net as its language
I want to displaysystem date in a textbox and enter the value into sql database when a button "submit" is clicked
how can do it?when ever this webpage is started the textbox should automatically take the date in the text box and when i click a button submit that date should enter into the sql database
how can i do this?
please help i have an urgent project to be submitted on this plzzzz
You can get the current date by using System.DateTime.Now, however, I suggest you go through the video's and tutorials fromhttp://asp.net/learn to learn how to use ASP.NET before starting on any "urgent" projects.
Hi,
In the Page Load event
first check
if(!ispostback)
then
textbox.text=datetime.now.tostring()
also same for the submit button accept send the value in the insert query rather then textbox
You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in databaseYou can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.
You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.
"please help i have an urgent project to be submitted on this plzzzz"#
sounds like homework..
Please help label text problem
i am making a form where der are 3 labels
EG. First name
Last name
Password
which have 3 textbox too.. now in labels the text i want it in extreme right.. like in vb.net we have textAlign right, left, center.. Rite
I want to do same in ASP.net i was looking in properties der is nothing like textalign. i tried to write <center> Firstname </center> in the html code(ASP.Net) but code dint work out.. please help me..If you are using an ASP.NET label, just move it to the desired position.
You need to look at an HTML tutorial, you should use DIVs and TABLEs to align your elements as you want.
www.w3schools.com/html
Good point, you should try using DIV's and inserting the desired text, that way you can justify it to the left, center, or right if you want.
please Help me find out a way!
I want a client to enter a 'key' in a textbox and click a button. then the entered value will be used to search a table in the MS-SQL database. The corresponding value found from that table will be used to search a second table. Data found from the second table will be bounded to the datagrid control at the page where the client entered the 'key'. What will be the way to achieve this? What will be the SQL command??
I'm not sure if I'm able to describe the problem. I'm a new user of ASP.NET. So please help.
Ishtiaque.
A stored procedure like this will work:
CREATE PROCEDUREdbo.Example
@.key1varchar(255)
AS
DECLARE@.key2varchar(255)
SELECT@.key2 = key2columnFROMTable1WHEREkey1column = @.key1
--The select below will return your results so you can bind to your grid:
SELECT*FROMTable2WHEREkey2column = @.key2
Thank you Sharbel_.
I made a stored procedure as you suggested and used it by a 'drag and drop' method in my webform. But as I mentioned I am a novice user of ASP.NET, could not utilize the sqlConnection or sqlCommand that resulted of doing so. Would you please let me know how to do so?
Thanks in advance.
Hi,
using System.Data.SqlClient; at the top in the .cs file
Create the connection and the command objects in the page_load or in the button click as
SqlConnection sqlcn =new SqlConnection(connectionString);
sqlcn.Open();
//creating and initialising a command object
SqlCommand sqlcm =new SqlCommand();
sqlcm.Connection = sqlcn;
sqlcm.CommandType = CommandType.StoredProcedure;
sqlcm.CommandText = StoredProcedure name;
sqlcm.ExecuteNonQuery();
HTH.
Friday, March 16, 2012
Please Help Select Statement Issue
I am trying to use a datagrid to display the data when the user enters a number into a textbox.
Below is my code:
Dim theVal As Integer = cInt(major.text , Integer)
' major is the name of the textbox
SELECT * FROM glmaster WHERE glmaster.major = theVal
When I put a number ie. 1000 where theVal is in the select statement, the datagrid displays the correct data. But as soon as I put a variable there I get an error.
Try "SELECT * FROM glmaster WHERE glmaster.major =" + theVal.ToString