Dynamic Source for a Datagrid, set in button handl

Results 1 to 2 of 2

Thread: Dynamic Source for a Datagrid, set in button handl

  1. #1
    Join Date
    Dec 1969

    Default Dynamic Source for a Datagrid, set in button handl

    Here is my issue. I&#039;m doing datagrid editing with the editcolumn. Under my current understanding and what I&#039;ve been able to acomplish, the only way I have been able to get the event to fire, is by binding the dataset to the datagrid in page_load. If i don&#039;t do a bind, when a person clicks edit, my debug runs through the page_load then just stops...doesn&#039;t run the event handler for the edit. However, once i do a bind with the data on the dataset in page_load or call a function that does , all of a sudden it calls the event handler properly.<BR><BR>So here is the issue, I have 3 different queries i run based on which link button they selected. Example: Dogs, Cats, Birds.. So they select a option, and i load a datatable and then they click edit on one of the values, and it works great, they can edit it. because in the page_load function i have the code look at a viewstate variable to see which table it should load.<BR><BR>However, if they click a different table link button, what happens is the system runs through page_load gets the old table based on the viewstate("table") variable, then the event handler for the new option (lets say it was dogs) gets fired and sets a viewstate variable to the new table viewstate("table") = dogs. i want to load. My solution has then been to create some javascript that is inserted into the users page and causes another post which the user doesn&#039;t really see because it happens imediately on page load, so the page_load runs again on the second post and gets the new viewstate variable value and loads the new table they clicked they wanted.<BR><BR>This seems entirely backwards to me, having the client IE browser do two posts to get that information just because the event handler runs after page load. There has to be something I&#039;m missing??????<BR><BR>under my assumptions since databind must occur so that the page knows what event handler it needs to fire, it needs to be in page_load. This gives me the problem of what if i don&#039;t yet know what table i want to load for this render?? not loading a table then inserting javascript to cause a post is just plain backwards.<BR><BR><BR>Please anyone with experience in asp .net, i could really use a pointer here.<BR><BR>Frank Walsh<BR>Frank.Walsh@gmail.com

  2. #2
    Join Date
    Dec 1969

    Default Not sure

    I completely understand what you&#039;re trying to do but this is what I would do:<BR><BR>Sub Page_Load<BR>If Not IsPostBack Then<BR>&#039;Bind the grid with an intial tablename so its knows what data to pull<BR>BindTheGrid("TableName")<BR>End If<BR>End Sub<BR><BR>Sub BindTheGrid(TableName as String)<BR>&#039;In this procedure you check the tablename passed and use the relevant query ( 1 of 3) to bind to the datagrid<BR>End Sub<BR><BR>Sub YourDataGrid_ItemCommand(s as Object, e as DataGridCommandEventArgs)<BR>&#039;When a button is clicked in the datagrid the relevant table query name is passed as the CommandName<BR>BindTheGrid(e.CommandName)<BR>End Sub<BR><BR>Then in your DataGrid<BR><BR>&#060;asp:ButtonColumn Text=Dogs CommandName=Dogs/&#062;<BR>&#060;asp:ButtonColumn Text=Cats CommandName=Cats/&#062;<BR>&#060;asp:ButtonColumn Text=Birds CommandName=Birds/&#062;<BR><BR>I might have completely mis-understood your aim but maybe the above will help.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts