Visual Studio 2008
References 에서 추가
- Right button Click on References
- Click "Add Reference.."
- Find "CrystalDecisions.Web" in .Net tab
Visual Studio 2008
References 에서 추가
- Right button Click on References
- Click "Add Reference.."
- Find "CrystalDecisions.Web" in .Net tab
Gridview의 특정 부분 필드에 적용하려고 하니 CSS가 제대로 작동하지 않았다.
구글한 결과..
The issue is certainly the size of the <input />
text boxes when in edit mode
Add the <EditRowStyle>
element to your gridview to give the edit row a CSS class
<asp:GridView ID="GridView1" runat="server">
...
<EditRowStyle CssClass="GridViewEditRow" /> <%-- add this --%>
</asp:GridView>
Now you can control the size of the textboxes with CSS
.GridViewEditRow input[type=text] {width:50px;} /* size textboxes */
.GridViewEditRow select {width:50px;} /* size drop down lists */
textbox 타입이 그냥 text 다.ㅡㅡ;;;
출처: http://csdotnetcode.blogspot.ca/2007/01/how-to-set-multiple-datakeynames-in.html
//To retrieve the values from a DataKeyNames collection,
//you can use "Key Names" or "index"
//Get the values with key names
string productId = GridView1.DataKeys[e.RowIndex].Values["ProductID"].ToString();
string orderId = GridView1.DataKeys[e.RowIndex].Values["OrderID"].ToString();
//Or
//Get the values with index
string productId = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string orderId = GridView1.DataKeys[e.RowIndex].Values[1].ToString();
위와 같이 사용하면 된다. 이걸 몰라서 삽질..ㅡㅡ;;
출처: http://csharpdotnetfreak.blogspot.com/2011/12/detailsview-edititemtemplate-dropdown.html
핵심은 control 을 찾아서 데이터를 입력하는 것이다.
아무튼 대단한듯..ㅡㅡ;;;
소스는 아래와 같다.
DropDownList And RadioButtonList In EditItemTemplate Of DetailsView to Edit
and Update In Asp.Net.
protected void DetailsView2_DataBound(object sender, EventArgs e) { if (((DetailsView)sender).CurrentMode == DetailsViewMode.Edit) { DataRowView row = (DataRowView)((DetailsView)sender).DataItem; RadioButtonList rblGender = (RadioButtonList)((DetailsView)sender).FindControl("rbGender"); DropDownList ddlStatus = (DropDownList)((DetailsView)sender).FindControl("ddlStatus"); rblGender.SelectedValue = row[2].ToString(); ddlStatus.SelectedValue = row[3].ToString(); } } protected void DetailsView2_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { RadioButtonList rblGender = (RadioButtonList)((DetailsView)sender).FindControl("rbGender"); DropDownList ddlStatus = (DropDownList)((DetailsView)sender).FindControl("ddlStatus"); SqlDataSource2.UpdateParameters["Sex"].DefaultValue = rblGender.SelectedValue; SqlDataSource2.UpdateParameters["Stauts"].DefaultValue = ddlStatus.SelectedValue; }
출처: http://www.dotnetspider.com/resources/7644-Bind-DropDownList-from-DataBase-Using-c.aspx
데이터베이스에 직접 연결하여 가져올 수 있지만,
DataSet을 이용하여 가져올 수 있다.
dataapater와 dataset을 생성한 후 데이터를 입력하면 된다.
핵심 코드는 다음과 같다.
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "FieldName"; // FieldName of Table in DataBase
DropDownList1.DataValueField = "FieldName";
DropDownList1.DataBind();
--- 원본 소스 ---
string s = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
private void bindtoddl()
{
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("select FieldName from TableName", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "FieldName"; // FieldName of Table in DataBase
DropDownList1.DataValueField = "FieldName";
DropDownList1.DataBind();
}