C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |



My Profile

Gifts

Active Members
TodayLast 7 Days more...



New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




GridviewItem


Posted Date: 27 Dec 2007      Total Responses: 2

Posted By: badarinarayana       Member Level: Bronze     Points: 2


Hi,

Pls do find my doubts and anybody answer soon.

In a GridView i have 3 columns .
In the 1st column i have placed a dropdownlist item template column. In the button_click i have to fill the dropdownlist with the datasource. other 2 columns are also dropdownlist and a textbox. Pls provide sample code to fill the 1st dropdownlist with database values.




Responses

Author: Ronak Thakkar    27 Dec 2007Member Level: GoldRating:     Points: 2
Hi,

Hope this will help u a lot....

====== GridView Coding ====================

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddl1" DataTextField = "varBranchName" DataValueField = "intGLCode" runat="server" DataSource='<%#BindSource()%>' ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddl2" runat="server" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

================= Code Behind ===========================


public partial class Default3 : System.Web.UI.Page
{
SqlDataSource ds;
DataSet abc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSource();
abc.Clear();//Clear DataSet to clear the first column of gridview when page loads
GridView1.DataSource = abc;
GridView1.DataBind();
}
}

public DataSet BindSource()
{
abc = new DataSet();
string connectinstring = ConfigurationManager.ConnectionStrings["RestaurantConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectinstring);
con.Open();
string command = "Select intglcode,varBranchName from Branch_Mst";
SqlCommand cmdSelect = new SqlCommand(command);
cmdSelect.Connection = con;
SqlDataAdapter adp = new SqlDataAdapter(cmdSelect);
DataSet dsnew = new DataSet();
adp.Fill(dsnew);
abc = dsnew;
return abc;
}
protected void Button1_Click(object sender, EventArgs e)
{
// Here we have data in abc dataset. So first column would be filled
BindSource();
GridView1.DataSource = abc;
GridView1.DataBind();
}
}

Regards,
Ronak Thakkar


Author: Mohan Kumar    27 Dec 2007Member Level: DiamondRating:     Points: 2
hi,

Check this link.

http://www.datagridgirl.com/articles.aspx


Post Reply
You must Sign In to post a response.
Next : How can I display dates in a column in asp.net between tw dates only
Previous : what is formatted output Response.Output..writeLine()
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

budget conference call

Contact Us    Privacy Policy    Terms Of Use