Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
who be dat? #1
Dynamically creating buttons per row: how?
I'm working on a web application that will use some datagrid and asp.net, an
asp.net Forum to be exact where people can leave posts and respond to posts
others have left. One page in particular displays rows with an
"interesting" column. What's interesting about this column is that it
displays some links followed by text (the message someone left), all in the
same column. These links represent actions a user can do. One link lets a
user reply to a message, the other link lets a user quote a message, link #3
lets a user delete a message, while the fourth link let's a user edit a
message. I'd like for these links to be buttons so I can put some code
behind them.
I'm relatively new to ASP.Net although I'm picking it up fairly well.
Datagrids in particular are giving me a bit of a fit although I'm slowly
learning the in's and out's of them. However, I've hit of a bricj wall. I
think I can do what I want with templates and such. When a button is
called, I can catch this event using the ItemCommand event and write the
necessary code to deal with what was clicked. Two problems I'm having:
1) All four buttons are not shown for each row everytime. At a minimum, a
row will display only two buttons, the reply and quote buttons. Edit will
only show up if the user who is logged in created the message for that
particular row. If the user didn't create that message in a given row, then
that user shouldn't see an edit button for that message. The delete button
works in a similar fashion although there are conditions where others can
delete a message. The point is, there are a total of four buttons that
maybe visible for each row but on some rows only 2 or 3 buttons will be
shown.
2) Due to the fact I like the way things look, I prefer to put the buttons
and text in the same column. Essientlly, the buttons will be at the top of
a column with the text of a message shown below the buttons, again in the
same column.
I suppose if I have to, I can put the buttons in their own column and have
the text in a seperate column, but I'd rather have them both in the same
column while figuring out a way to have buttons present or not present on a
per row basis.
Is this possible? I've seen quite a few examples of adding controls (such
as buttons) to a column, but I've never seen an example where each row could
have a different amount of buttons in the same column unless the datagrid
has gone to edit mode for a row, for example, which I'd rather not do.
Plus, I'm not seeing much where it comes to adding controls and adding text
after a control although I suppose I could add a label after the buttons in
the column and fill it with the text representing the message...
Any thoughts on this would be greatly appreciated. I ordered an ASP.Net
book on controls which was recommended on DatagridGirl.com, but it won't be
here for a day or two. I'd really like to get past this ASAP.
Sorry for the long post and thanks!
Chris Smith
who be dat? Guest
-
Dynamically adding buttons to each row: how?
I'm working on a web application that will use some datagrid and asp.net, an asp.net Forum to be exact where people can leave posts and respond to... -
adding buttons dynamically
Hello All Can i add a button to a form dynamically durin runtime Something like on(load) var bt:Button = new Button( this.add(bt) // this... -
Dynamically creating buttons in custom datagrid control
Hi, I am creating a custom control datagrid. For each dynamically created column I've added a button in the header that will filter based on the... -
Problem with Dynamically Creating Link Buttons
Hello, This is my code behind code for dynamic link button creation: strUrl = "<asp:LinkButton CommandName='Onet3_Cd'... -
Creating onClick event for dynamically (programatically) created buttons
Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button =... -
ashelley@inlandkwpp.com #2
Re: Dynamically creating buttons per row: how?
You can dynamically create controls in the itemdatabound event.
Create a empty template column as a container for your buttons and
onitemdatabound you can create buttons and add them to the cell.
-Adam
ashelley@inlandkwpp.com Guest
-
who be dat? #3
Re: Dynamically creating buttons per row: how?
Ahhh.... OK. This sounds like a good beginning. I think I fully
understand what you are saying.
Would it be possible to put text after these controls so everything could be
in one column? I suppose I could put a label in after after the buttons and
set it's text property to the text of the message to be displayed...
Chris Smith
<ashelley@inlandkwpp.com> wrote in message
news:o0tld0pj51hq0nehp7jotp6rin866ct86p@4ax.com...> You can dynamically create controls in the itemdatabound event.
> Create a empty template column as a container for your buttons and
> onitemdatabound you can create buttons and add them to the cell.
>
> -Adam
>
who be dat? Guest
-
ashelley@inlandkwpp.com #4
Re: Dynamically creating buttons per row: how?
On Thu, 24 Jun 2004 12:05:55 -0400, "who be dat?" <whatever@dot.com>
wrote:
yes, exactly. You can use a label or even a literalcontrol.>Ahhh.... OK. This sounds like a good beginning. I think I fully
>understand what you are saying.
>
>Would it be possible to put text after these controls so everything could be
>in one column? I suppose I could put a label in after after the buttons and
>set it's text property to the text of the message to be displayed...
>
-Adam
ashelley@inlandkwpp.com Guest
-
who be dat? #5
Re: Dynamically creating buttons per row: how?
Alright, I got it to add the buttons that I wanted just as you said to do.
However, thing is they don't do anything!! I put in an ItemCommand event
handler in my code to handle the buttons when they were clicked. Thing is,
it never even goes to the ItemCommand subroutine. Well, unless I click a
page at the bottom of the grid to go to a different page. It doesn't use
the PageIndexChanged even anymore, it goes to ItemCommand. Not a huge deal,
I can check the commandname which is "page" when you want to go to a
different page. I can put the code for a new page in an if/end if block.
However, none of the buttoms ever make it to the ItemCommand event.
I used trace to follow the code execution. Once the page is loaded, I can
click a new page in the footer. The path of the execution automatically
goes to ItemCommand, doesn't start at any other place, just right at this
event handler. However, when I click a button it doesn't go to Itemcommand
even handler. Instead, clicking a button acts like it's just posting back
to the page. The code immediately goes back to the load_page event. Since
it's a postback, the page is just redisplayed.
Good news: I can insert buttons and I can insert/not insert the buttons that
I need or want on a per row basis. Bad news, they don't do anything. I've
tried everything I can think of and tried to figure out why, but I'm at a
loss to explain it. Any ideas? Hope you are still there. Thanks!
Chris Smith
<ashelley@inlandkwpp.com> wrote in message
news:5k5md01g6rredv5kt5pe3v30t2039d4jf9@4ax.com...be> On Thu, 24 Jun 2004 12:05:55 -0400, "who be dat?" <whatever@dot.com>
> wrote:
>> >Ahhh.... OK. This sounds like a good beginning. I think I fully
> >understand what you are saying.
> >
> >Would it be possible to put text after these controls so everything couldand> >in one column? I suppose I could put a label in after after the buttons>> >set it's text property to the text of the message to be displayed...
> >
> yes, exactly. You can use a label or even a literalcontrol.
>
> -Adam
who be dat? Guest



Reply With Quote

