468,765 Members | 949 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Selecting specific data to download

Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.

What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the
list, I want to put in a checkbox, basically to select
that line.

At the bottom, I want a button that will know what lines
I have selected, and I can then continue with what the
button is to do (namely, to generate a CSV file of the
selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

Nov 16 '05 #1
5 1335
Hi Dave,

Both Windows Forms and ASP.NET have DataGrids and CheckBoxes and each
technology would implement this differently. Perhaps posting to the
appropriate news group for the technology your using will get you the best
answer.

Joe
--
http://www.csharp-station.com

"Dave" <da***@revilloc.remove.this.bit.com> wrote in message
news:1c****************************@phx.gbl...
Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.

What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the
list, I want to put in a checkbox, basically to select
that line.

At the bottom, I want a button that will know what lines
I have selected, and I can then continue with what the
button is to do (namely, to generate a CSV file of the
selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

Nov 16 '05 #2
Dave,

In order to do this, you would have to add another column to your data
source, which would be of type boolean. This way, you can check off the
items in the data source that you want to process.

Then, when you click your button, just process the rows where that
column value is true. You can easily apply a filter to a DataTable using a
DataView class (and then just cycle through what the DataView returns to
you).

I don't believe the current DataGrid supports multiple row selection (or
at least, I haven't been able to figure out how to get it programatically).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <da***@revilloc.remove.this.bit.com> wrote in message
news:1c****************************@phx.gbl...
Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.

What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the
list, I want to put in a checkbox, basically to select
that line.

At the bottom, I want a button that will know what lines
I have selected, and I can then continue with what the
button is to do (namely, to generate a CSV file of the
selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

Nov 16 '05 #3
Hi Nicholas,

I am using ASP.NET (with C#)

Thanks for your reply. I have done a bit more research on
the net and not found anything.

I have added a checkbox column in my datagrid. The
columns are not automatically generated.

I have a link button at the bottom of the page,
marked "Click here to download". In the linkbutton event,
I just do a response.write to show that the event has
been reached.

How can I tell what check boxes are ticked?

Thanks.
Best regards,
Dave Colliver.
http://www.SwindonFOCUS.com

-----Original Message-----
Dave,

In order to do this, you would have to add another column to your datasource, which would be of type boolean. This way, you can check off theitems in the data source that you want to process.

Then, when you click your button, just process the rows where thatcolumn value is true. You can easily apply a filter to a DataTable using aDataView class (and then just cycle through what the DataView returns toyou).

I don't believe the current DataGrid supports multiple row selection (orat least, I haven't been able to figure out how to get it programatically).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <da***@revilloc.remove.this.bit.com> wrote in messagenews:1c****************************@phx.gbl...
Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.

What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the list, I want to put in a checkbox, basically to select
that line.

At the bottom, I want a button that will know what lines I have selected, and I can then continue with what the
button is to do (namely, to generate a CSV file of the
selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

.

Nov 16 '05 #4
Dave,

I would recommend adding the boolean column to the data source itself,
and then bind to that in the grid. Then, bind the checkbox column to the
column in the data source, and you can check it when the button is pressed.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <da***@revilloc.remove.this.bit.com> wrote in message
news:1d****************************@phx.gbl...
Hi Nicholas,

I am using ASP.NET (with C#)

Thanks for your reply. I have done a bit more research on
the net and not found anything.

I have added a checkbox column in my datagrid. The
columns are not automatically generated.

I have a link button at the bottom of the page,
marked "Click here to download". In the linkbutton event,
I just do a response.write to show that the event has
been reached.

How can I tell what check boxes are ticked?

Thanks.
Best regards,
Dave Colliver.
http://www.SwindonFOCUS.com

-----Original Message-----
Dave,

In order to do this, you would have to add another

column to your data
source, which would be of type boolean. This way, you

can check off the
items in the data source that you want to process.

Then, when you click your button, just process the

rows where that
column value is true. You can easily apply a filter to

a DataTable using a
DataView class (and then just cycle through what the

DataView returns to
you).

I don't believe the current DataGrid supports

multiple row selection (or
at least, I haven't been able to figure out how to get

it programatically).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <da***@revilloc.remove.this.bit.com> wrote in

message
news:1c****************************@phx.gbl...
Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.

What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the list, I want to put in a checkbox, basically to select
that line.

At the bottom, I want a button that will know what lines I have selected, and I can then continue with what the
button is to do (namely, to generate a CSV file of the
selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

.

Nov 16 '05 #5
Hi Nicholas.

Thanks for your help so far. I am slowly getting closer,
but not quite there yet.

What I am not sure about is how to retrieve the checked
lines to use as a filter...

Code snippetts below.
************************************************** ***

private void GetSchoolsData(string SchoolType, string
SchoolLocation, string SchoolRange)
{
try
{
conn.Open();

SqlCommand cmd =
conn.CreateCommand();
cmd.CommandText = "Select
0 as TickColumn, SchoolID, [School Name], Address1,
Headteacher from SchoolsData where [School Name] between
@NameStart and @NameEnd and Area like @Area order by
[School Name]";
// All parameters defined here...

SqlDataAdapter SqlDA =
new SqlDataAdapter();
SqlDA.SelectCommand = cmd;
DataSet SchoolData = new
DataSet();
SqlDA.Fill
(SchoolData, "SchoolsList");
SchoolsListGrid.DataSource = SchoolData.Tables
["SchoolsList"];
SchoolsListGrid.DataBind
();

}
finally
{
conn.Close();
}

}
private void LinkButton2_Click(object
sender, System.EventArgs e)
{
Response.Write("Clicked here");
}
************************************************** **
<asp:DataGrid id="SchoolsListGrid" runat="server"
Font-Names="Arial" Font-Size="X-Small"
AutoGenerateColumns="False"

CellPadding="4" BackColor="White"
BorderWidth="1px" BorderStyle="None" BorderColor="#3366CC"

Width="100%">

<SelectedItemStyle Font-Bold="True"
ForeColor="#CCFF99"
BackColor="#009999"></SelectedItemStyle>

<ItemStyle ForeColor="#003399"
VerticalAlign="Top" BackColor="White"></ItemStyle>

<HeaderStyle Font-Bold="True"
ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>

<FooterStyle ForeColor="#003399"
BackColor="#99CCCC"></FooterStyle>

<Columns>

<asp:TemplateColumn
HeaderText="X">

<ItemTemplate>

<asp:CheckBox
id=CheckBox2 runat="server" Checked='<%# Convert.ToBoolean
(DataBinder.Eval(Container.DataItem, "TickColumn")) %>'>

</asp:CheckBox>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn
HeaderText="School Name">

<ItemTemplate>

<asp:LinkButton
id=LinkButton1 OnCommand="SchoolsLink_Click"
CommandArgument='<%#DataBinder.Eval
(Container.DataItem, "School Name")%>'
CommandName="SchoolLink_Click" Runat="server">

<%
#DataBinder.Eval(Container.DataItem, "School Name")%>

</asp:LinkButton>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn
HeaderText="Address">

<ItemTemplate>

<%#DataBinder.Eval
(Container.DataItem, "Address1")%>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn
HeaderText="Head Teacher">

<ItemTemplate>

<%#DataBinder.Eval
(Container.DataItem, "Headteacher")%>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

<PagerStyle HorizontalAlign="Left"
ForeColor="#003399" BackColor="#99CCCC"
Mode="NumericPages"></PagerStyle>

</asp:DataGrid>

<asp:LinkButton id="LinkButton2" runat="server"
Font-Names="Arial" Font-Size="X-Small" ToolTip="Click to
download the selected schools">Click here</asp:LinkButton>

<FONT face="Arial" size="2">&nbsp;to download
selected schools</FONT>

************************************************** ****

The idea is to tick the boxes, then click the LinkButton
to download. Currently, I have just got a response.write
in the linkbutton event, but here will be where I should
manage the selected list.

I am probably looking at this from the wrong direction. I
couldn't see how to bind the column when I had a checkbox
in it.

Any sample code that can set me straight would be
appreciated.

Best regards,
Dave Colliver.
http://www.BlackpoolFOCUS.com

-----Original Message-----
Dave,

I would recommend adding the boolean column to the data source itself,and then bind to that in the grid. Then, bind the checkbox column to thecolumn in the data source, and you can check it when the button is pressed.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <da***@revilloc.remove.this.bit.com> wrote in messagenews:1d****************************@phx.gbl...
Hi Nicholas,

I am using ASP.NET (with C#)

Thanks for your reply. I have done a bit more research on the net and not found anything.

I have added a checkbox column in my datagrid. The
columns are not automatically generated.

I have a link button at the bottom of the page,
marked "Click here to download". In the linkbutton event, I just do a response.write to show that the event has
been reached.

How can I tell what check boxes are ticked?

Thanks.
Best regards,
Dave Colliver.
http://www.SwindonFOCUS.com

-----Original Message-----
Dave,

In order to do this, you would have to add another

column to your data
source, which would be of type boolean. This way, you

can check off the
items in the data source that you want to process.

Then, when you click your button, just process the

rows where that
column value is true. You can easily apply a filter to

a DataTable using a
DataView class (and then just cycle through what the

DataView returns to
you).

I don't believe the current DataGrid supports

multiple row selection (or
at least, I haven't been able to figure out how to get

it programatically).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dave" <da***@revilloc.remove.this.bit.com> wrote in

message
news:1c****************************@phx.gbl.. .
Hi all,

Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.
What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of

the
list, I want to put in a checkbox, basically to select that line.

At the bottom, I want a button that will know what

lines
I have selected, and I can then continue with what the button is to do (namely, to generate a CSV file of the selected data).

Is there an easy way to do this?

I am still fairly new to C# so step by step would be
appreciated. (I am not asking for the job to be done,
just some guidance.)

Thanks in advance for your help.

Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com

.

.

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by webhigh | last post: by
3 posts views Thread by Simon G Best | last post: by
19 posts views Thread by Ben Gribaudo | last post: by
12 posts views Thread by Lawrence Oluyede | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.