IT Community - Software Programming, Web Development and Technical Support

ASP.NET Data Controls

This is a discussion on ASP.NET Data Controls within the ASP and ASP.NET Programming forums, part of the Web Development category; hi, I am getting an error :\Users\tmarie\Documents\MSDN\test\secure_members\ OrderSearch.aspx(26) : error BC30451: Name 'CustomerID' is ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #61 (permalink)  
Old 08-27-2007, 07:58 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Question Re: ASP.NET Data Controls

hi,
I am getting an error
:\Users\tmarie\Documents\MSDN\test\secure_members\ OrderSearch.aspx(26) : error BC30451: Name 'CustomerID' is not declared.

SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
~~~~~~~~~~
C:\Users\tmarie\Documents\MSDN\test\secure_members \OrderSearch.aspx(27) : error BC30455: Argument not specified for parameter 'arguments' of 'Public Function Select(arguments As System.Web.UI.DataSourceSelectArguments) As System.Collections.IEnumerable'.

SqlDataSource1.Select()
~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\tmarie\Documents\MSDN\test\secure_members \OrderSearch.aspx(35) : error BC30455: Argument not specified for parameter 'arguments' of 'Public Function Select(arguments As System.Web.UI.DataSourceSelectArguments) As System.Collections.IEnumerable'.

SqlDataSource1.Select()
~~~~~~~~~~~~~~~~~~~~~~~
I thought that i declared 'CustomerID at the top.
and where in the Page_Load event do i put the if post back?
code i have right now.
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" %>
<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
Session("CustomerID") = Nothing

If User.Identity.IsAuthenticated Then
If User.IsInRole("admin") Then
If Request("CustomerID") IsNot Nothing Then
Session("CustomerID") = Request("CustomerID")
End If
Else
Session("CustomerID") = User.Identity.Name
End If
End If
'SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
'SqlDataSource1.Select()
'GridView1.DataBind()
End If


If Not IsPostBack Then
SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
SqlDataSource1.Select()
GridView1.DataBind()
End If

End Sub

Protected Sub Search_Click(ByVal sender As Object, ByVal e As System.EventArgs)SqlDataSource1.SelectCommand = "SELECT * FROM [test.csv] WHERE " & DropDownList1.SelectedItem.Text & " = " & txtSearch.Text
SqlDataSource1.Select()
GridView1.DataBind()
End Sub

</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" SkinID="KylieSkin"
EmptyDataText="There are no data records to display." AllowPaging="True" AllowSorting="True"
PageSize="20">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE ([CUSTOMERID] = ?)" />
<selectparameters>
<asp:SessionParameter Name="CUSTOMERID" SessionField="CUSTOMERID" Type="String" />
</selectparameters>
</asp:SqlDataSource> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
<aspropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="Customer_PO">Customer P.O.</asp:ListItem>
</aspropDownList>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="search" /><br />
</asp:Content>
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #62 (permalink)  
Old 08-27-2007, 07:59 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

If you look at my code in the previous post, I have take removed the SelectParameters and using SelectCommand itself to create my query. That is the one of the reason why you are getting the error.
Secondly in the Page_Load event in the Not IsPostback section, I have remarked that you have to check your CustomerID there. So I was assuming that you would have a variable called CustomerID and was using this variable in the SelectCommand. In your code, you are using it as a function called CustomerID() and not as a variable.
If Not IsPostBack Then
' Do your checking for CustomerID
dim CustomerID as Integer = Cint(Session("CustomerID"))
SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " &
CustomerID
SqlDataSource1.Select()
GridView1.DataBind()
End If
In the above code, I haven't done any error checking.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #63 (permalink)  
Old 08-27-2007, 08:16 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Question Re: ASP.NET Data Controls

hi guys,

I have my ODS in SP, I've problem to choose the column in the Table (the part which I bold the font below), it is syntax error.
Any comment? Thanks for helps..
SELECT
SampleToolItem .*,
Creators.UserName ItemCreatorDisplayName

FROM
SampleToolItem
INNER JOIN aspnet_users AS Creators ON Creators.UserId = SampleToolItem.ItemCreatorId
Where
SampleToolItem.@ddl = @tb
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #64 (permalink)  
Old 08-27-2007, 08:17 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

SampleToolItem.@ddl = @tb
@ddl is a variable and you cannot (as far as I know) reference a column name like this.
SampleToolItem.ItemID = @ItemID
In the above SampleToolItem is your tablename, ItemID is your column(or field) in your table and @ItemID is the variable that you are passing.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #65 (permalink)  
Old 08-27-2007, 08:19 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Thumbs up Re: ASP.NET Data Controls

hi venkat,

Ya,that is the problem. Actually I have a search function for GV which consist of a Dropdownlist(search by) and a Textbox.
So, I can't assign the static column name in the SP but have to depend on the selection by user.
Maybe there are alternative solution for this? Or how can I reference to the column name selected by user?(the @ddl)
Thanks a lot!
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #66 (permalink)  
Old 08-27-2007, 08:31 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi kingmaker,

If you are setting the SelectCommand then you can do this.
SqlDataSource1.SelectCommand = "SELECT * FROM [test.csv] WHERE " & ColumnName & " = " & searchCriteria
If you are using Stored procedure and columnname and searchcriteria as parameters, then you have to do
DECLARE @SQLQUERY VARCHAR(1000)

SET @SQLQUERY = N'SELECT * FROM TABLE1 WHERE ' + QUOTENAME(@COLUMNNAME) + ' = ' + @SearchCriteria

EXEC (@SQLQUERY)
In the above QuoteName is used to thwart Sql injection.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #67 (permalink)  
Old 08-27-2007, 08:35 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Thumbs up Re: ASP.NET Data Controls

hi,

When I do like that, it force me to key in the textbox's text exactly same as the ddl's item value.
Example:
<aspropDownList ID="ddlSearch" runat="server">
<asp:ListItem Value="ModelName">Model Name</asp:ListItem>
<asp:ListItem Value="ModelNo">Model No</asp:ListItem>
</aspropDownList>
if I key in "name1", the error is:
Invalid column name 'name1
if I key in "ModelName", display all the GV rows
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #68 (permalink)  
Old 08-27-2007, 08:36 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Thumbs up Re: ASP.NET Data Controls

hey guys,

I solve it by:

WHERE
CASE
WHEN @ddl='ModelName' THEN ModelName
WHEN @ddl='ModelNo' THEN ModelNo
END
=@tb
Thanks for help
Wish to know other method if u have other ideas,
thanks
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #69 (permalink)  
Old 08-28-2007, 04:28 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

Hi guys,

I am trying send an email when a row in my gridview has been updated based on a checkbox in grideview = true.
I Keep getting the error "object reference not set to an insatnce of an object"
I am assuming that this is because the code isn't finding the checkbox.
I have editing enable for the gridview.....What is the name of the checkbox ( in edit mode ) in the grid view.
My aspx page contains <asp:CheckBoxField DataField="ApprovedBy_HR"
What should my code behind use to refernce this..
I tried the following
Dim VarHRApproved As CheckBox = CType(GridView1.FindControl("ApprovedBy_HRCheckBox "), CheckBox)
If VarHRApproved.Checked = True Then
'create the mail message
Thx in advance,
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #70 (permalink)  
Old 08-28-2007, 04:36 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hey H2o,

Since we don't know the name of the control, you simply pull the control out of the specific cell's control collection. For example, if your CheckBoxField was the first column of your GridView, then you'd retrieve the CheckBox reference like so:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;

if (gvr.RowType == DataControlRowType.DataRow)
{
CheckBox chk = gvr.Cells[0].Controls[0] as CheckBox;
}
}
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #71 (permalink)  
Old 08-28-2007, 04:43 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Default Re: ASP.NET Data Controls

Hi

I have it working now but I get an email sent for EACH row that has the check box ticked.
But What I want is only an email to be sent on update of the current row in edit mode.
So I need to remove the syntax that references "for each row".
Which bits do I remove inorder to just send email for the current row that is in edit mode.
thx
My working code is
Dim r As GridViewRow
For Each r In GridView1.Rows
Dim VarHRApproved As CheckBox = CType(r.Cells(0).Controls(0), CheckBox)
If VarHRApproved.Checked = True Then
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #72 (permalink)  
Old 08-28-2007, 04:48 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

Use the GridView.RowUpdating event instead and do something like this:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim gvr As GridViewRow = GridView1.Rows(e.RowIndex)

Dim chk As CheckBox = CType(gvr.Cells(2).Controls(0), CheckBox)

If chk.Checked Then
'Create email message
End If
End Sub
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #73 (permalink)  
Old 08-28-2007, 04:52 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

Thanks ..
I now have it working thanks to you.
For anyone else that needs to know.the below code will fire off an email when BOTH checkboxes (within a gridview update) are ticked.
Code for sending email not included.
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim gvr As GridViewRow = GridView1.Rows(e.RowIndex)
Dim VarMGRApproved As CheckBox = CType(gvr.Cells(1).Controls(0), CheckBox)
Dim VarHRApproved As CheckBox = CType(gvr.Cells(2).Controls(0), CheckBox)
If VarHRApproved.Checked = True And VarMGRApproved.Checked = True Then
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #74 (permalink)  
Old 08-28-2007, 05:20 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question Re: ASP.NET Data Controls

hey guys,

can any one help me.....

I Use a Gridview which Contains Lots of Records with Paging...
I have a checkBox Column ,i want to persist state of Checked Checkboxes while Moving From One Page To Another.
Example:-Suppose a Check a Checkbox on First Page 6th Row and Move to 2nd Page and Check 10th Row,and Then when i naviagte back to 1st Page i want to Show the 6th Row Checked in First Page and Viceversa...


thanks in advance.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #75 (permalink)  
Old 08-28-2007, 05:29 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 246
H2o is on a distinguished road
Default Re: ASP.NET Data Controls

hi,

For this you can store your check box state along with id in a collection. Store it in Session and retrieve back on item databound event and set the state of the checkboxes. The name of the checkboxes can be your keycolumn. This will help you to retrieve and set the values easily irrespective of the page. Make sure that you are updating the collection values before grid refreshes the data. Storing the values in key-value pairs in Hashtable will make your task easier.
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #76 (permalink)  
Old 08-28-2007, 05:31 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question Re: ASP.NET Data Controls

Hi,

Any Code Example Which u Can Suggest of would be better for me to Understand?
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #77 (permalink)  
Old 08-28-2007, 05:52 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

Hi, Oxygen:
You can save the value of checkbox in Session when PageIndexChanging and retrieve them from Session when PreRender. Here is an example code.
Hope it helps.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Response.Write(GridView1.PageIndex.ToString());
int d = GridView1.PageCount;
bool[] values = new bool[GridView1.PageSize];
CheckBox chb;
int count = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
chb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (chb != null)
{
values[i] = chb.Checked;
}
}
Session["page" + GridView1.PageIndex] = values;
}


protected void GridView1_PreRender(object sender, EventArgs e)
{
if (Session["page" + GridView1.PageIndex] != null)
{
CheckBox chb;
bool[] values = (bool[])Session["page" + GridView1.PageIndex];
for (int i = 0; i < GridView1.Rows.Count; i++)
{
chb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
chb.Checked = values[i];
}
}
}
If you have any doubts about it, please feel free to post back.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #78 (permalink)  
Old 08-28-2007, 05:59 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

Suppose i need to Delete some records on 1st page,2nd page and etc..
Checkbox State is Persisted and now on Submit button Click i want to take all the checked values from all the pages.
for identifying checked checckboxes im using
For i= 0 to gridview.rows.count
But in Mycase What happens is i have set Page Size to 20 while the Total Records are 100.
i get only values of the current page.

Please Suggest
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #79 (permalink)  
Old 08-28-2007, 06:01 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

Hi,Oxygen

The GridView control is used to display a colletion of datas. The colletion can be a DataTable, DataSet and so on. If the gridview can be paged, it seems like it has one or more pages, displaying different datas from the colletion.
But, in fact, not all the datas is retrieved from the collection when the gridview is bound to it. Only those which will be displayed in current page like from the 5th row to the 10th in the table are retrieved. So you can only access those rows with the gridview.
To sovle your problem, you should loop through the datas in database, not the rows in GridView.
Take a datatable for example. You should add a new column to the datatable, which is a bool type to save the value of the checkbox, when you checked or unchecked the row in gridview, modify the values of the row in datable. The datatable should be save in Viewstate or session.
I hope it can help.
If you have any doubts about it, please feel free to post back.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #80 (permalink)  
Old 08-28-2007, 07:35 AM
garunprasad garunprasad is offline
D-Web Trainee
 
Join Date: Mar 2007
Location: Chennai
Posts: 45
garunprasad is on a distinguished road
Send a message via ICQ to garunprasad Send a message via AIM to garunprasad Send a message via MSN to garunprasad Send a message via Yahoo to garunprasad Send a message via Skype™ to garunprasad
Default Re: ASP.NET Data Controls

hi guys,

Is it possible to do this? I have a screen with a datagrid and detailsview. You can select a record in the datagrid, modify it in the detailsview. Works fine. I need the ability to search through the datagrid and position it at the inputted ID. I.e. the record key is called 'ProductID' and the table contains 1,000 records. I don't want the user to have to look through 50 pages to find the product, then edit it. I want to accept input from a textbox and then position the grid at that record, and if possible, force it to be selected so the detailsview will let them edit it.
__________________
G.A.P
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On