ASP.NET - gridview1.datasource ???

Asked By avula
03-Feb-12 03:11 AM
Hi every One,

add specific rows of datareader to gridview???
  kalpana aparnathi replied to avula
03-Feb-12 03:24 AM
hi,

Try this way:

Write this below code within you want to bind gridview

gridview1.DataSource = ds;
gridview1.DataMember = "tablename";
 
this will automatic load that table into the gridview.
 
 
To add a new row to a datagridview:
 
DataRow newRow;
 
newRow = gridview1.NewRow();
newRow["column1name"] = "somevalue";   // make sure it in string format.
newRow["column2name"] = "somevalue";
 
gridview1.Rows.Add(newRow);
  dipa ahuja replied to avula
03-Feb-12 03:24 AM
Try this simple way
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    bindGrid();
  }
}
void bindGrid()
{
  SqlDataAdapter da = new SqlDataAdapter("select * from TableName", "Connection String");
  DataTable dt = new DataTable();   
  da.Fill(dt);
  GridView1.DataSource = dt;
  GridView1.DataBind();
}
 

Or you can here change the select Query based on some condition using the "Where" condition or you can create a dynamic table and bind it to the gridview
  Web Star replied to avula
03-Feb-12 03:25 AM
if you want to bind datasource of gridview with filter row than don't use DataReader than use DataTable and than you will bind filter row with gridview as follows
eg.
gridview1.DataSource = dTable.Select("AutoID = 10"); 
 gridview1.DataBind(); 
  D Company replied to avula
03-Feb-12 03:28 AM
Hello Friend,

Is this what your looking for.
//your query and connection

SqlCommand com = new SqlCommand("Your  Query", con);

//use reader to fetch data
SqlDataReader
read = com.ExecuteReader();

DataSet ds = new DataSet();

 

//giv it to data set
DataTable
dt = new DataTable("TableName"
);

ds.Tables.Add(dt);

//load it into dataset
ds.Load(read,
LoadOption.PreserveChanges, ds.Tables[0]);

//assign data set to your control here you can fetch a particular column value and assign it.
gridControl1.DataSource = ds.Tables[0].Column["passthename of column or index also"];

//ds.Tables[0] place the dot after this and check with availiable options

Hope it helps!!
Regards
D
  avula replied to dipa ahuja
03-Feb-12 03:29 AM
            sorry my  need is different, thanks to all

              if (isPending(reader.getstring(0)) == false)
              {
                   GridView1.DataSource = reader;
              }
              GridView1.DataBind();

    if the record not pending then and only add the record other wise skip the record to add into gridvew
Create New Account
help
alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page. What are the 2 important parts of a master page? The following are the 2 important parts of a master page 1. The Master Page itself 2. One or more Content Pages Can Master Pages be nested? Yes, Master Pages
Text = = "All" && DropDownList_state.SelectedItem.Text = = "All" && DropDownList_city.SelectedItem.Text = = "All" && CheckBoxList1.SelectedIndex = = -1) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = true && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = false && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = false && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = true && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = true && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = false && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area 0].Selected = = true && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area
SqlHelper()" private SqlHelper() {} / / / <summary> / / / This method is used to attach array of SqlParameters to a SqlCommand. / / / / / / This method will assign a value of DbNull to any parameter with a direction of commandParameters"> An array of SqlParameters to be added to command< / param> private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters) { if( command = = null ) throw new ArgumentNullException( "command" ); if( commandParameters ! = null ) { foreach (SqlParameter connection, transaction, command type and parameters / / / to the provided command / / / < / summary> / / / <param name = "command"> The SqlCommand to be prepared< / param> / / / <param name = "connection"> A valid SqlConnection, on which to execute this the connection was opened by the method, otherwose is false.< / param> private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection ) { if null) { AttachParameters(command, commandParameters); } return; } #endregion private utility methods & constructors #region ExecuteNonQuery / / / <summary> / / / Execute a SqlCommand (that returns no resultset and takes no parameters) against the database specified in / / / the connection for the set of SqlParameters return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null); } / / / <summary> / / / Execute a SqlCommand (that returns no resultset) against the database specified in the connection string / / / using the provided connection string return ExecuteNonQuery(connection, commandType, commandText, commandParameters); } } / / / <summary> / / / Execute a stored procedure via a SqlCommand (that returns no resultset) against the database specified in / / / the connection string using the provided just call the SP without params return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); } } / / / <summary> / / / Execute a SqlCommand (that returns no resultset and takes no parameters) against the provided SqlConnection. / / / < / summary> / / / <remarks> / / / e
following code into the show button click, SqlConnection con = new SqlConnection ( "Connection String" ); con.Open(); SqlCommand com = new SqlCommand ( "select * from employee" , con); SqlDataReader read = com.ExecuteReader(); DataSet ds = new DataSet (); DataTable dt = new DataTable ( "Table1" ); ds.Tables.Add(dt); ds.Load(read, LoadOption .PreserveChanges, ds.Tables[0]); gridControl1.DataSource = ds.Tables[0]; This small application for DataGrid allows SqlConnection conn = new SqlConnection(conStr); / / Open the connection conn.Open(); / / Create a data adapter object SqlDataAdapter adapter = new SqlDataAdapter( " SELECT * FROM MyTable" , conn); / / Create a DataSet object DataSet ds = new DataSet(); / / filling the DataSet strSQLconnection = "Data Source = dbServer;Initial Catalog = testDB;Integrated Security = True"; SqlConnection sqlConnection = new SqlConnection(strSQLconnection); SqlCommand sqlCommand = new SqlCommand( "select * from table1", sqlConnection); sqlConnection.Open(); SqlDataReader reader = sqlCommand.ExecuteReader(); GridView1.DataSource = reader
n how to bind data to the radiobutton frm table. . ? plz help me hi, aspx page code < asp:RadioButtonList id = "RadioButtonList1" runat = "server" > < / asp:RadioButtonList > < asp:Button ID = "btnTest" Runat = "server New SqlClient.SqlConnection(strConn) Dim ds As DataSet = New DataSet() Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn) Cmd.Fill(ds, "Emptbl") Dim dt As New DataTable dt = ds.Tables(0 to do tht. plz help me Hi, will u please send me ur aspx(design page), that i can understand wht u want to do? hi, Figure 1 The Wizard control the Next button rendered in main area. The default value is “Auto”. Listing1: QuizWizard.aspx <%@ Page Language = "C#" %> <!DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http: / / www.w3 True" / > < SideBarButtonStyle ForeColor = "White" / > < / asp:Wizard > < / div > < / form > < / body > < / html > do this remain quest also <%@ Page Language = "C#" MasterPageFile = "~ / user.Master" AutoEventWireup = "true" CodeBehind = "taketest.aspx.cs" Inherits = "online.taketest" Title = "Untitled Page" %> <asp:Content ID = "Content1" ContentPlaceHolderID = "head" runat = "server"> < / asp:Content> <asp:Content ID = "Content2" ContentPlaceHolderID me. . . . . . . . . . . . . plz mam. . . . . help me. . . . . . . . hi, 1) find bind qusetion to label: like these cs.Page protected void Page_Load( object sender, EventArgs e) { LoadQuestion(); } protected void LoadQuestion() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "Dbcon" ].ConnectionString); SqlCommand com = new SqlCommand( "Select Question from table" , conn); / / com.Connection = conn; com.Connection.Open(); SqlDataReader