How to change data in grid after you change the SQL select for the data adapter

ASP.NET

    Next

  • 1. Having a column with a checkbox where when the checkbox changes, it updates a table.
    I have a datagrid with a checkbox as a column that I read from a DB. I would like to have it so that when a user clicks the checkbox it will automatically save it to the DB so there doesn't have to be a submit/save button. I realize I'm going to have to use autopostback and I plan on using an Ajax UpdatePanel so it only updates the datagrid - not the whole page. How can I implement this? TIA - Jeff.
  • 2. wrap text in datagrid cell
    here is a cleaner version of a question I posted yesterday. I have tried many versions of the code below but cannot get the column to wrap. I am using asp.net 2.0 visual studio 2005. ultimately I will be adding template columns as well, but really need this column to wrap. thanks for your help <asp:datagrid id="myDataGrid" style="Z-INDEX: 100; LEFT: 20px; POSITION: absolute; TOP: 260px" runat=server AllowSorting="True" Font-Size="X-Small" Font-Names="Verdana" ForeColor="Black" GridLines="None" CellPadding="2" BackColor="LightGoldenrodYellow" BorderWidth="1px" BorderColor="Tan" Width="100px" Height="304px" OnPreRender="myDataGrid_PreRender" AutoGenerateColumns="False" BorderStyle="Solid" CellSpacing="2"> <Columns> <asp:BoundColumn DataField="contact_email" ReadOnly="True" HeaderText="Emailx"> <ItemStyle Wrap="True" ></ItemStyle> <HeaderStyle Width="5px" Wrap=true/> </asp:BoundColumn> </Columns> </asp:datagrid> public void myDataGrid_PreRender(object sender, System.EventArgs e) { myDataGrid.Columns[0].ItemStyle.Width = 30; myDataGrid.Columns[0].ItemStyle.Wrap = true; }
  • 3. DataGrid Footer DropDownList OnSelectedIndexChanged
    I have 2 dropdownlists in the Footer of a datagrid: ddlStartTime and ddlEndTime. Both contain values like "1:00 AM", "1:15 AM", "1:30 AM", etc. There is also a label named lblTimeDiff. I need to dynamically popolate lblTimeDiff.Text (during onselectedindexchanged of ddlEndTime) with the difference in minutes between ddlStart and ddlEnd in the Footer. I'm sure javascript will come into play here but I have absolutely no idea how to define the eventhandler and scripting. I can do this in tsql using datediff(mi, start_time, end_time), just can't seem to dynamically put the return value in the label without a postback to the server. Any ideas? Thank you very much.

How to change data in grid after you change the SQL select for the data adapter

Postby tom c » Wed, 07 Jun 2006 11:15:20 GMT

I have an ASP.net webform with a datagrid on it.

I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

The rest of the code in Sub Page_Load is

        OleDbDataAdapter1.Fill(DsCategories1)
        If Not IsPostBack Then
            DataGrid1.DataBind()
        End If

This works fine on the initial load of the the webform.  If I want to
change the SQL command to load different data into the grid after the
form is loaded, and do that with a cmdButton, what code to I put under
the cmdButton to reload the webform or grid with the new sql select?


Re: How to change data in grid after you change the SQL select for the data adapter

Postby PeterKellner » Fri, 09 Jun 2006 23:46:11 GMT




You would call DataBind() on your datagrid.  This rexecutes the get
code in  your bound datasource.
Peter Kellner
 http://www.**--****.com/ 

Similar Threads:

1.How to change data in grid after you change the SQL select for the data adapter

I have an ASP.net webform with a datagrid on it.

I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

The rest of the code in Sub Page_Load is

        OleDbDataAdapter1.Fill(DsCategories1)
        If Not IsPostBack Then
            DataGrid1.DataBind()
        End If

This works fine on the initial load of the the webform.  If I want to
change the SQL command to load different data into the grid after the
form is loaded, and do that with a cmdButton, what code to I put under
the cmdButton to reload the webform or grid with the new sql select?

2.Changing row height in a data grid without changing font size

How do you change the row height in a data grid - I do not want to increase 
the height by changing my font size. My product is a touch screen so I have 
to make the row height large enought for a finger press.

3.reflect changes in data bound control when underlying data table changes

[Little correction]

Hi,
I have a form on which I have 2 datagrid view.
1) for table "route" - Structure : route char(3), dock int
2) for table "lanes" - Structure: laneid char(3), laneName char(6), 
lanetype char(2), dock1 int, dock2 int, dock3 int, dock4 int, dock5 int

The various docks in table lanes are actually values in the table 
route's dock. But it's not a foreign key. Nor is the dock unique in the 
route table. There can be multiple entry for a single value of dock. 
Also database can be change under any circumstances.

For DataGridView of table lanes, I needed to display the available docks 
in a combo box. So, I created another dummy table (dummy_docks) whose 
select query is

"select distinct dock from route order by dock" 

This dummy_docks table is used as data source for dock1, dock2...., 
dock5 columns (combo box columns) of the data grid view of table lanes.

When the application initializes, the adapter fills the table 
dummy_docks and the values are displayed in the combo box of the data 
grid view of table lanes.

But after that if any row is added to table route then the new value of 
dock is not reflected in the combo box in the data grid view of lanes.

I tried to update the changes in route table by calling update on the 
data adapter and clear & re-fill the table dummy_docks using the 
adapter, but it doesn't help.

How can I make the changes reflect in the data bound combo box of the 
data grid view.

Thanks & Regards,
Ashutosh



Return to ASP.NET

 

Who is online

Users browsing this forum: No registered users and 23 guest