请帮助我在asp.net中执行此代码 [英] plz help me out this code to do in asp.net
本文介绍了请帮助我在asp.net中执行此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个代码,其中应从数据库的网格视图中显示更多下拉列表,其中
它们应该显示在列中...
请帮我...
代码:
aspx的代码:
i have written a code where more dropdown list should be displayed in grid view from the database where
they should be displayed in columns...
plz help me out...
code:
code for aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdateClientMapping.aspx.cs"
Inherits="AttendanceWinmethods.UpdateClientMapping" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Client Mapping Details
</div>
<div>
<br />
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
Width="500px" OnRowDataBound="GridView2_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="ParentClientID">
<HeaderStyle HorizontalAlign="Left" Width="150px" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%#Eval("ParentClientID")%>
<asp:DropDownList ID="ddlParentClientID" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IntermediateClientID">
<HeaderStyle HorizontalAlign="Left" Width="150px" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%#Eval("IntermediateClientID")%></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlIntermediateClientID" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActualClientID">
<HeaderStyle HorizontalAlign="Left" Width="150px" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%#Eval("ActualClientID")%></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlActualClientID" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
aspx.cs的代码:
code for aspx.cs:
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.Data.SqlClient;
using System.Configuration;
namespace AttendanceWinmethods
{
public partial class UpdateClientMapping : System.Web.UI.Page
{
string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindData();
}
#region Business Layer
private void BindData()
{
//Bind the grid view
GridView2.DataSource = GetClientMappingDetails();
GridView2.DataBind();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlParentClientID = (DropDownList)e.Row.FindControl("ddlParentClientID");
//Bind subcategories data to dropdownlist
ddlParentClientID.DataTextField = "ClientName";
ddlParentClientID.DataValueField = "ClientID";
ddlParentClientID.DataSource = RetrieveParentClientID();
ddlParentClientID.DataBind();
DataRowView dr = e.Row.DataItem as DataRowView;
ddlParentClientID.SelectedValue = dr["ParentClientID"].ToString();
}
}
#endregion;
#region Data Layer
private DataSet GetClientMappingDetails()
{
if (ViewState["ClientIDS"] != null)
return (DataSet)ViewState["ClientIDS"];
string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "WM_Prc_Get_ClientMappingDetails";
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
return ds;
}
#endregion;
public object ds { get; set; }
protected DataTable RetrieveParentClientID()
{
string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
SqlConnection con = new SqlConnection(strConnection);
// String str = "select CM.ParentClientID, CD.ClientName from ClientDetails as CD,ClientMapping as CM where CD.ClientID=CM.ParentClientID";
String str = "select ClientName, ClientID from ClientDetails";
SqlCommand cmd = new SqlCommand(str, con);
//cmd.Connection = con;
//cmd.CommandText = "WM_Prc_Get_ClientMappingDetails";
//cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
// DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
return dt;
}
public object dt { get; set; }
}
}
代码格式化完成,删除了".
Code Formatting done and "" is removed.
推荐答案
我想将所有这些集成到另一列中,我该怎么做.
i want to integrate all those into another column how can i do it.
这篇关于请帮助我在asp.net中执行此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文