C# - GridView From CodeBehind Select Row And Postback?
I am having to create a GridView 100% in C# CodeBehind. I have it selecting a row and posting back using this code:
void dataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
((Convert.ToInt32(e.Item.ItemIndex.ToString())) + 2) +
This does post back but then how do I get the ID of the row the user clicked on?
View 2 Replies (Posted: Mar 7 at 21:23)
Related Forum Messages For ASP.NET category:
Forms Data Controls :: How To Select Gridview Without Postback
I have a gridview which is ShowSelectButton = "False"
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
to select a gridviewrow but it causes a postback whenever I select a row. Is there a way to allow selecting a gridview row which will not cause a postback??
Posted: Feb 23, 2010 04:14 PM
View 1 Replies!
Cross Page Postback From Codebehind?
I want to do something similar to what happens when you click an asp.net button that has a PostBackURL set. I've tried Server.Transfer but the URL doesn't change (which is something I want). Is there a better way to do this, or alternatively is there a way to make Server.Transfer display the correct URL?
Posted: Aug 16 10 at 17:02
View 2 Replies!
Have To Select Gridview Row Twice For Dropdown To Select Correctly
I'm using the code below to extract data from a gridview and populate it into textboxes for the days and two drop downs for Project and Category.
For some rows in the gridview everything but the category ddl populates correctly. If I click the row a second time the category ddl displays the correct category.
why I have to click twice for some rows?
Posted: Oct 13 10 at 19:27
View 2 Replies!
Dynamically Displayed Usercontrol Not Firing Postback Event On Select?
i have a very strange issue with a user control we are dynamically loading on an asp.net web page(.net 2.0). the user control has 3 dropdowns, one of which has a selectedindexchanged event attached to it (which loads the third dropdown with a set of values).
the weird thing is, if there are currently any invalid fields (where field validators have been activated) in other parts of the form, when you go to select the drop down in question on the FIRST change it does nothing, but then when you change the index again it works perfectly! i dont understand how the event wont fire for the first change, but for every change thereafter.
However, if all these fields are filled in correctly above the usercontrol, it fires off the selectedindexchanged event correctly.
in regards to validation i have disabled ALL POSSIBLE validation in order to try and eliminate it as a culprit, so i dont understand how validation can be affecting the usercontrol.
Posted: Aug 20 10 at 6:37
View 1 Replies!
Can A Button In A GridView Run Some Code In A Codebehind
I have a vb.net page that has a gridview. I've added a select button in the last column on the right, and when the user clicks that button (seebold below) , I'd like to run some code in the code behind. Is that possible? How do I tell the button to do some work from the code behind?
Posted: Jun 10, 2009 02:31 PM
View 13 Replies!
C# - How To Program Edit Button For Gridview Through Codebehind
I am trying to generate a gridview dynamically through codebehind. So I am making all the columns through code using BoundField and other controls.Now I am trying to to put a edit button in the gridview sand program that(I made a RowEditing handler). Right now all my code is in the page_load but when I hit the edit button in the gridview I get 2 gridviews back on post back.So I tried to put a isPostback if statement to stop this but then I just get a error back saying it can't find the handler.
Posted: Mar 4 10 at 0:58
View 1 Replies!
Forms Data Controls :: Gridview Doing In Codebehind?
I have multiple questions about doing gridview in code behind.I used this code to fill my gridview at runtime.
My questions are:1. How to edit the column headers? When I bind the database to my gridview, obviously, the column headers of the database will be binded. For example "First_Name", I want to edit the column so I can omit the underscore.2. How to edit the column width?
Posted: Jul 12, 2010 06:30 AM
View 15 Replies!
Web Forms :: Controls In Gridview EditItemTemplate Not Available In CodeBehind Or DataSources?
i saw this post on[URL] so the problem is .... if there is a datasource in some editeitem template in grid view .... it won't be accessible from out of the edit-item field.....
here's my code...
that i have here is ID-column which contains a linqdatasource taking a where parameter from a dropdownlist and they are both in the same edit-template field.
and i have in another column (CourseTypeID-column ... edit-item template) a dropdownlist ..... now this dropdownlist i want to bind it to the linqdatasource exists in the ID-column (edit-item template)..... is that possible in the designer (or from) not code behind ..... and how ????
Posted: Feb 16, 2010 05:19 PM
View 4 Replies!
Forms Data Controls :: Nested DDL From Second Table In GridView - SQL To Codebehind
First, what I am showing here works fine, and I know how to do this if the nested control comes from the same bound table. I could leave it at that, but I don't like SQL code in my aspx page, and want to move it. I'm keeping it simple here, but I can move it to a data access layer later on..... for now, I want to understand what's going on when the page loads and the nested control is rendered and populated. WHAT I LEARN FROM THIS WILL BENEFIT ME ACROSS THE BOARD - NOT just for this instance!!!
My question is, how to grab the SQL query from the aspx page for the NESTED control and move it to the codebehind. I'd LOVE to also move the Selected Value parameter if possible, but mainly want to get the SQL out of the page. I KNOW HOW TO DO THIS for a GridView or any control, but I DO NOT know how to do it for a NESTED CONTROL from a different table - i.e. WHERE it fires (on GridViewEditing or GridViewUpdating or PageLoad....) so I can put in the SQL where it belongs.... and I'm PRETTY darn SURE this can be done without a 'foreach' loop. For discussion's sake here, imagine
1. DATABASE: simple table with employee_ID, employee_name, employee_city as fields
2. DATABASE: simple table containing all cities (city, cityval)
2. simple GridView that displays these 3 fields in same order ON VIEW
3. Template field for city. On PAGE LOAD, this is a simple label bound to the 'city' field. HOWEVER - On EDIT (with edit button), the field changes to a nested DropDownList that is bound to the 'city' table, NOT to the employee table.
4. Selected value is the current city for employee The PROC you see here in the edit item SQL is actually SELECT * FROM [cities] ORDER BY [city_name]
<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="False"
<asp:BoundField DataField="employee_ID" HeaderText="ID" ReadOnly="True" />
<asp:TemplateField HeaderText="Employee Name">
<asp:Label ID="lblEmployeeName" runat="server" Text='<%#Eval("employee_name")%>'></asp:Label>
<asp:TextBox ID="txtEmployeeName" runat="server" Text='<%#Eval("employee_name")%>'></asp:TextBox>
<asp:DropDownList ID="cboCity" runat="server"
DataSourceID="SqlDataSource1" DataTextField="city" DataValueField="cityval"
SelectedValue='<%# Bind("employee_city") %>'>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=XXXXXXXXXXXX;Initial Catalog=xxxxxxx;Integrated Security=True"
<asp:Label ID="lblEmployeeCity" runat="server" Text='<%# Bind("employee_city") %>'></asp:Label>
ALL I want to do is move the SQL Query in the EDIT template above to the code behind. I just don't know WHERE or WHEN in the code this fires and how to handle it when the table is different from the original GridView table. AND the cboCity.SelectedValue, if possible.
Posted: Mar 08, 2011 01:33 AM
View 2 Replies!
Asp.net - Custom Paging/sorting For GridView Filled By CodeBehind Datasource?
I'm coding a report page.In this page,there are two date fields for user to filter the date and the GridView is filled depending on these dates in the CodeBehind (When user click the button view).Now I want toimplement a paging/sorting feature for this GridView.I've researched and see there are default paging for GridView which is not very efficient (my report table may have thousands of records) and custom paging but this requires using ObjectDataSource (which I don't use).Thus anyone can recommend me some approaches that are best used in this situation?
Posted: Nov 15 10 at 4:19
View 1 Replies!
Forms Data Controls ::couple Gridview To Objectdatasource Which Couples To Codebehind Methods?
I have a strange thing going on. I have a a custom tableadapter (.xsd) and in codebehind a method like:
Note that my datakeyname = ArticleID. When I add a DeleteParameter in the list, as when I select in the wizard the delete method from codebehind, which will go to the business layer which goes ultimately to the dal layer where the tableadapter does its job,then I get error. When I remove afterwards manually the deleteparameter it works just fine.How come? Also when I alter the methods, build again and then open up the wizard of the objectdatasource again then it refreshes the gridview and I lose all the columns.
Posted: Oct 10, 2009 09:32 PM
View 2 Replies!
Forms Data Controls :: GridView Sorting, Paging And DataBinding / When Control Causes A Postback GridView Is No Longer Sorted?
I'm trying to extend the GridView control to enable sorting and paging for any situation.
When using my control I am fetching data from a database and filling a DataSet with it, then binding the GridView upon every page load. My first question would be, is this the correct approach?
To sort the GridView I am overriding the OnSorting method which stores the sort expression and direction in the ViewState, then creates a DataView and utalises the Sort method to sort the underlying data. It then sets the Data Source to this DataView and rebinds the GridView.
Paging is handled by OnPageIndexChanging which simply sets the PageIndex property and again rebinds the GridView.
My problem is; when any control causes a postback my GridView is no longer sorted, presumably because it is persistently rebound. If I don't rebind it then the GridView is empty on postback since the data isn't automatically stored in the ViewState. I have considered saving the data source in the ViewState but I would assume that this is bad practice for large amounts of data? - also DataViews are not seralisable.
The only solution I can think of currently is to override OnDataBound and sort the data every time. This results in a double sort when paging triggers a postback which seems inefficient. Code illustration of this below,
I'm looking for the cleanest 'best practice' solution as this is a learning exercise more than anything else.
Posted: Jan 10, 2011 10:38 AM
View 12 Replies!
Select Row In GridView
I have a gridview control with a Delete Link Command. My question is how can I determine which row the user is on when they click the Delete Link. This seems so easy. I have been researching the hell out out of this and I cant find anything. There seems to be a whole lot of information floating around out there (Including Porn) that you dont need. And very little of the common problems that we face as programmers.
Posted: Dec 21, 2009 08:36 PM
View 4 Replies!