how to bind data in griedviw in asp.net

Posted by Shanky11 under ASP.NET on 3/6/2013 | Points: 10 | Views : 1947 | Status : [Member] | Replies : 3
this is the design of griedview whch i need to bind to database
how can i get ths ???

<asp:GridView ID="contactgrdview" runat ="server" AutoGenerateColumns="false" AllowPaging ="true">
<Columns>

<asp:BoundField DataField="username" HeaderText="Name" />
<asp:BoundField DataField ="Mobile" HeaderText ="Mobile-No" />

<asp:TemplateField HeaderText ="Select">

<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>




Responses

Posted by: Pavanandey on: 3/6/2013 [Member] Bronze | Points: 25

Up
0
Down
string strCon = "Data Source=" ";Initial Catalog=" ";Integrated Security=True";
string strSQL = "select username,Mobile from <<table>>";

SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

DataTable table = new DataTable();
dataAdapter.Fill(table);
contactgrdview.DataSource = table;
contactgrdview.DataSource = dbBindSource;



Thanks
Pavan Kumar
Mark Answer if this fits the need

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 3/7/2013 [Member] Starter | Points: 25

Up
0
Down
if still dint come set AutoGenerateColumns="true"

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 3/7/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.IO;
using System.Data.SqlClient;


public partial class UploadandViewPDF : System.Web.UI.Page
{
string strconn = ConfigurationManager.ConnectionStrings["cnnLocal"].ConnectionString;
string desc = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}




private void BindGrid()
{
try
{
SqlConnection con = new SqlConnection(strconn);
con.Open();
string str = "select * from emp";
SqlCommand cmdins = new SqlCommand(str);
cmdins.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("ShowGrid", con);
DataSet ds = new DataSet();
da.Fill(ds, "pdffiles");
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
desc = ex.Message;
}

}





}


Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response