473,831 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button Column Select.

Hi all,
I have a datagrid with Button column select in form of hyperlink. On
the same page, I have another datagrid that insert data and one
column(Name) has Names of a user that is inserting data(using windows
authentication) .
Now this is how it's supposed to work: When any user want to see data
about a particular user it's a matter of selecting his name and the
data Writen by the selected user should be the only ones to be shown.
I got some examples on Google but they all seem not to be working.
When a user is selected the page remains the same data is not
selected. How would can I solve this problem?
My code looks like this:
HTML part:
<Columns>
<asp:ButtonColu mn HeaderText="Ope rations"
DataTextField=" TeamOperation" ButtonType="Lin kButton"></
asp:ButtonColum n>
</Columns>
and code behind:
private void dgoperation_Ite mCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
SqlCommand myCommand=new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="select * from dbo.DashBoard where Name =
@Billing";
myCommand.Param eters.Add(new SqlParameter("@ Billing",SqlDbT ype.VarChar,
50));
myCommand.Param eters["@Billing"].Value= dgbilling;
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds);
dgis.DataSource =ds;
dgis.EditItemIn dex = -1;
dgis.DataBind() ;
}

dgis: this is the datagrid that where user inserts data.
dgbilling: this is the datagrid with the name list.
Thanks.

May 18 '07 #1
18 1529
I have corrected my statement and this time I'm getting this error:
"Object reference not set to an instance of an object."
And the error source:
Line 219: myCommand.Comma ndText="select * from dbo.DashBoard where
Name Like @Billing";
Line 220: myCommand.Param eters.Add(new
SqlParameter("@ Billing",SqlDbT ype.VarChar,50) );
Line 221: myCommand.Param eters["@Billing"].Value= bc.Text;
Line 222: SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
Line 223: DataSet ds = new DataSet();
This is my code:
<Columns>
<asp:ButtonColu mn HeaderText="Ope rations"
DataTextField=" TeamOperation" ButtonType="Lin kButton"
CommandName="Se lect"></asp:ButtonColum n>
</Columns>
My code behind:
private void dgoperation_Ite mCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
System.Web.UI.W ebControls.Link Button bc=new
System.Web.UI.W ebControls.Link Button();
bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamBilling");
SqlCommand myCommand=new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="select * from dbo.DashBoard where Name Like
@Billing";
myCommand.Param eters.Add(new SqlParameter("@ Billing",SqlDbT ype.VarChar,
50));
myCommand.Param eters["@Billing"].Value= bc.Text;
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds);
dgis.DataSource =ds;
dgis.EditItemIn dex = -1;
dgis.DataBind() ;
}
How can I solve this?
Thanks

May 18 '07 #2
On May 18, 3:14 pm, rcoco <nclau...@yahoo .cawrote:
myCommand.Conne ction=con;
What is 'con'? Did you created a SqlConnection reference already?

For example,

SqlConnection con = new SqlConnection(" my_connection_s tring");

May 18 '07 #3
Hi Alexey,
con is:
SqlConnection con = new SqlConnection(" user
id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ard;");
Thanks

May 21 '07 #4
On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
Hi Alexey,
con is:
SqlConnection con = new SqlConnection(" user
id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo *ard;");
Thanks
Well, but where do you create it?

The code above looks correct and I can only guess that possibly your
connection object is not a global available reference.

Is it a code-behind class? If yes, did you compiled it?

May 21 '07 #5
On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
Hi Alexey,
con is:
SqlConnection con = new SqlConnection(" user
id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo **ard;");
Thanks

Well, but where do you create it?

The code above looks correct and I can only guess that possibly your
connection object is not a global available reference.

Is it a code-behind class? If yes, did you compiled it?
Yes it's a code behind.
I think the problem was
System.Web.UI.W ebControls.Link Button bc=new
System.Web.UI.W ebControls.Link Button();
bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB*
illing");
So I have now tryed Writing the code like this.
System.Web.UI.W ebControls.Butt onColumn bc=new
System.Web.UI.W ebControls.Butt onColumn();
bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S elect") ;
SqlCommand myCommand=new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="select * from dbo.DashBoard where Name =
@operation";
myCommand.Param eters.Add(new
SqlParameter("@ operation",SqlD bType.VarChar,5 0));
myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
con.Open();
myCommand.Execu teNonQuery();
con.Close();
dgis.EditItemIn dex=-1;
Fill();
Bind();
But when compiling I get this error
C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
type 'System.Web.UI. Control' to
'System.Web.UI. WebControls.But tonColumn'
I'm not sure if I'm on the right track! What do you think?
Thank you very much.

May 21 '07 #6
On May 21, 11:41 am, rcoco <nclau...@yahoo .cawrote:
On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
Hi Alexey,
con is:
SqlConnection con = new SqlConnection(" user
id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ***ard;");
Thanks
Well, but where do you create it?
The code above looks correct and I can only guess that possibly your
connection object is not a global available reference.
Is it a code-behind class? If yes, did you compiled it?

Yes it's a code behind.
I think the problem was
System.Web.UI.W ebControls.Link Button bc=new
System.Web.UI.W ebControls.Link Button();
bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB**
illing");
So I have now tryed Writing the code like this.
System.Web.UI.W ebControls.Butt onColumn bc=new
System.Web.UI.W ebControls.Butt onColumn();
bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S el*ect") ;
SqlCommand myCommand=new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="select * from dbo.DashBoard where Name =
@operation";
myCommand.Param eters.Add(new
SqlParameter("@ operation",SqlD bType.VarChar,5 0));
myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
con.Open();
myCommand.Execu teNonQuery();
con.Close();
dgis.EditItemIn dex=-1;
Fill();
Bind();
But when compiling I get this error
C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
type 'System.Web.UI. Control' to
'System.Web.UI. WebControls.But tonColumn'
I'm not sure if I'm on the right track! What do you think?
Thank you very much.
First of all, remember, the "code behind" classes must be compiled
into an assembly, which is placed by VS.NET in the \bin directory.
When you get an error during compilation, you cannot run the actual
code, because your classes simply did not compiled and a DLL in the
\bin directory was not updated.

Regarding your LinkButton.

I'm not very well understood why you used this

<asp:ButtonColu mn DataTextField=" TeamOperation" ...

Maybe you can explain, what you did supposed to get there

I suppose, you wanted to have this

<asp:ButtonColu mn CommandName="Te amOperation"... .

which can be simply accessed as

e.CommandName

in your dgoperation_Ite mCommand() function

e.g.

myCommand.Param eters["@operation "].Value= e.CommandName;

without any extra code.

However, in this case I don't see the sense of the

"select * from dbo.DashBoard where Name = @operation";

May 21 '07 #7
On May 21, 1:21 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 21, 11:41 am, rcoco <nclau...@yahoo .cawrote:


On May 21, 9:51 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 21, 7:11 am, rcoco <nclau...@yahoo .cawrote:
Hi Alexey,
con is:
SqlConnection con = new SqlConnection(" user
id=utldbuser;"+ "password=utldb user;"+"server= utlhq202;"+"dat abase=IS_dashbo ****ard;");
Thanks
Well, but where do you create it?
The code above looks correct and I can only guess that possibly your
connection object is not a global available reference.
Is it a code-behind class? If yes, did you compiled it?
Yes it's a code behind.
I think the problem was
System.Web.UI.W ebControls.Link Button bc=new
System.Web.UI.W ebControls.Link Button();
bc=(System.Web. UI.WebControls. LinkButton)e.It em.Cells[0].FindControl("T eamB***
illing");
So I have now tryed Writing the code like this.
System.Web.UI.W ebControls.Butt onColumn bc=new
System.Web.UI.W ebControls.Butt onColumn();
bc=(System.Web. UI.WebControls. ButtonColumn)e. Item.Cells[0].FindControl("S el**ect") ;
SqlCommand myCommand=new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="select * from dbo.DashBoard where Name =
@operation";
myCommand.Param eters.Add(new
SqlParameter("@ operation",SqlD bType.VarChar,5 0));
myCommand.Param eters["@operation "].Value= bc.DataTextFiel d;
con.Open();
myCommand.Execu teNonQuery();
con.Close();
dgis.EditItemIn dex=-1;
Fill();
Bind();
But when compiling I get this error
C:\Inetpub\wwwr oot\Dash_Board\ DashBoard.aspx. cs(210): Cannot convert
type 'System.Web.UI. Control' to
'System.Web.UI. WebControls.But tonColumn'
I'm not sure if I'm on the right track! What do you think?
Thank you very much.

First of all, remember, the "code behind" classes must be compiled
into an assembly, which is placed by VS.NET in the \bin directory.
When you get an error during compilation, you cannot run the actual
code, because your classes simply did not compiled and a DLL in the
\bin directory was not updated.

Regarding your LinkButton.

I'm not very well understood why you used this

<asp:ButtonColu mn DataTextField=" TeamOperation" ...

Maybe you can explain, what you did supposed to get there

I suppose, you wanted to have this

<asp:ButtonColu mn CommandName="Te amOperation"... .

which can be simply accessed as

e.CommandName

in your dgoperation_Ite mCommand() function

e.g.

myCommand.Param eters["@operation "].Value= e.CommandName;

without any extra code.

However, in this case I don't see the sense of the

"select * from dbo.DashBoard where Name = @operation";- Hide quoted text -

- Show quoted text -
Thanks
TeamOperation is a columns that has a list of users of the website. So
by
<asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
names in datagrid "dgoperatio n".
Thanks

May 21 '07 #8
On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
Thanks
TeamOperation is a columns that has a list of users of the website. So
by
<asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
names in datagrid "dgoperatio n".
Thanks- Hide quoted text -
Ok, I think, I got it

Then try

myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;

assuming that "Operations " is the first column of the grid

May 21 '07 #9
On May 21, 3:43 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 21, 2:26 pm, rcoco <nclau...@yahoo .cawrote:
Thanks
TeamOperation is a columns that has a list of users of the website. So
by
<asp:ButtonColu mn DataTextField=" TeamOperation" ... Im diplaying the
names in datagrid "dgoperatio n".
Thanks- Hide quoted text -

Ok, I think, I got it

Then try

myCommand.Param eters["@Billing"].Value= e.Item.Cells[0].Text;

assuming that "Operations " is the first column of the grid
Still does not select any data. All it does its like the page is just
being refreshed.
Thanks
May 21 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1395
by: Mark | last post by:
Hi all, I have generated a dynamic DataTable which I then bind to a datagrid in my application. What I want to do is add a column which contains a button relating to each row in the datatable. When a user clicks on the button an event is raised so I can show the user more information pertaining to information in the current row.. I have tried the following..
3
2797
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine, but users have requested a confirmation message pop up so the user can confirm the delete. I can not quite get this to work. Here are the facts: I am working in the Microsoft Development Environment 2003 (Version
2
2444
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
3
13759
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
3
1646
by: CharlesA | last post by:
Hi folks, I really need help with the following scenario, I'm going to describe as well as a I can what the setup is and what I can't understand I'm using the framework 1.1 using ASP.net with C# I have a datagrid that is bound to a datasource (through ADO.net) and all that works
2
2630
by: Arsalan Ahmad | last post by:
Hi, May be I am a newbie, or may be i dont have that much insight in following systems ..i.e. why i have some confusions as below: In many websites, when search is performed on some keywords (not only including google which perform general search but other sites which perform seach on a particular type of item in their database) then many search results are obtained (for example more than 100 or even more than 1000) but only limited...
1
1242
by: nclauder | last post by:
Hi all, I have a datagrid with Button column select in form of hyperlink. On the same page, I have another datagrid that insert data and one column(Name) has Names of a user that is inserting data(using windows authentication). Now this is how it's supposed to work: When any user want to see data about a particular user it's a matter of selecting his name and the data Writen by the selected user should be the only ones to be shown. I got...
3
5524
by: WiscCard | last post by:
This seems simple enough, but I am having problems. I have a table of customer information. I have a form with various combo boxes displaying unique customer information (in this case, zone and broker, but I'll add others before it is done. I want each user to choose what they want out of the combo boxes, then hit the command button, which will display the results on a customized form. If they choose both combo boxes, it works gerat. The...
1
1653
by: Forumtroll | last post by:
I have a Web User Control that parses an XML file and renders a Form based on the XML. The problem is that I create a button on the bottom of the form that will fire off a subscribeable event, but somehow the button never seem to fire that particular event. The code is attached below. using System; using System.Collections;
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3960
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.