Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid - re: Pushbutton functionality

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
I am realizing that learning .NET is like learning how to use a snowboard. You take alot of falls initially and then control begins to set in....

I am very impressed with the functionality of the DataGrid but am having a heck of a time getting a "fire" event to come off a Pushbutton. Most of the examples in my books, and on the that 99% of the time one should preferably use a "Linkbutton" which fires without problem.

The Pushbutton, when bound to a field, "looks great"...but I had to abandon that approach for a Linkbutton so as not to hamper development time. I tried to send info to a text box on the "SelectIndexChanged" event of the Grid, which I then planned to set to Auto Postback to process. But no luck (realizing of course that I am not "Grid" competent at this point).

The DataGrid is extremely useful, but I have found most of the articles on the net deal with putting functionality and data into the Grid; and very few on getting it out.

Without spending any time, anyone out there have a hint on this? Or a good link? I include here a link to a page from a young fellow who summarized his experience with getting data out of a Grid - just in case one wants to review it.

Thanks in advance.

 
Hey Isadore,

Could you explain a little bit more about what it is you're trying to do?

i.e. If a user clicks the button, the record selected is shown in a different screen, OR when a user clicks the button, the record is editable in the datagrid Or something else, etc.

Changing from a link to a push button is actually very easy. If you are using vs.net, all you have to do is go into the columns collection dialog of the datagrid and change the button style to push instead of link. Voila!

Datagrids are very easy to use once you "get the hang of them". You'll get there, no worries.
:)

Just let us know a bit more and we'll go from there.

Jack
 
If I understand correctly you are trying to add a function call from the click even of your "datagrid created button".

Have been struggling myself on this subject. The right solution is to add an attribute to the button from the Item_Created event of the Datagrid.

from there you can access all the controles of teh template items, edit templates and so on...

hth
 
Alcar, thanks..

Problem is quite straight forward (now there's a .NET phrase you won't see often)...I'm so use to Access events, etc..

Yes, the Pushbutton "looks" and "feels" better to me than a link button, so thanks for the suggestion...I I get it working I will post...will be putting snippets up from time to time...I am a novice, in every way....
 
Everyone is a novice. If you don't consider yourself a novice, then you will not learn much... (my two cents)

here is some additional help for you :

private void MyDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType lit = e.Item.ItemType;
if (lit == ListItemType.Item)
{
ImageButton imbDelete = (ImageButton) e.Item.FindControl("imbDelete");
imbDelete.Attributes.Add("OnClick", "javascript: return confirm('Are you sure you want to delete this record?');");
}
}

hth
 
Maybe I missed something, but from vs.net you could also just add a button column. In the dialog (or in the html) you could then set which command function of the datagrid's that button will be linked to (the Delete, Item, Edit, Update, etc.)

Then, when the button is pressed, it will trigger whatever code you write within that command sub.

Jack
 
My mistake. Sorry. The issue wasn't the "Select" pushbutton, that works just fine, no problems.

The problem was that I wanted the buttons not to all say "Select", but I wanted the button bound to a field, such as "ID", and each button then displays the "ID" for that record - to me it made sense, then I wouldn't have to use valuable Column space to repeat the field again.

But, when I had the button reveal the text of the record, that is where I lost the "event"... hope that makes it a bit clearer....
 

doesn't

<asp:button ID=&quot;button1&quot; Runat=&quot;server&quot; Text='Select <%# DataBinder.Eval(Container.DataItem, &quot;ID&quot;).ToString()%>' CommandName=&quot;Select&quot;/>

work?
 
I think I may have it. It sounds like when you bind the button the name of it is changing as well as the text. When the name changes it can't find the event for that button since it doesn't exist.
ie. Button was cmdSelect Event Handler is cmdSelect_click
You bind it
Button is now cmdStuff Event Handler is still cmdSelect_click
The event handler should in this case be cmdStuff_click.
However it is impossible to dynamically create event handler names.
To fix the problem you just make sure that only the button text is changed not the name.

Remember I am speaking purely theoretically I haven't actually tried this myself.

Hope this helps [peace]
 
Zarcom et al. I'll give it a try, and get back with ya. Thanks for the input. The datagrid &quot;aka flagship&quot; of .NET is so useful, I want to make it as fine on the user end as possible.

One tidbit: For those of you using Studio.NET (I know, I should be on SDK)...remember this: I did a &quot;Find and Replace&quot; in the codebehind .vb file - and thinking in the Access vba world...didn't realized that it operated across ALL .aspx.vbc files!! After two events of this all was lost...(but of course, I had my backup...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top