|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: |
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="WareHouseAdmin.test2" %>
<!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>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" onrowcancelingedit="GridView1_RowCancelingEdit" onrowediting="GridView1_RowEditing" onrowupdated="GridView1_RowUpdated" onrowupdating="GridView1_RowUpdating" DataSourceID="SqlDataSource1">
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" onupdated="SqlDataSource1_Updated" onupdating="SqlDataSource1_Updating"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
</form>
</body>
</html>
-----------------------------
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WareHouseAdmin
{
public partial class test2 : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
SetupData();
}
protected void Page_Load(object sender, EventArgs e)
{
BuildGrid();
if (!IsPostBack)
{
BindGrid();
}
}
private void SetupData()
{
string connection = ConfigurationManager.ConnectionStrings["warehouseConnectionString"].ConnectionString;
this.SqlDataSource1.ConnectionString = connection;
this.SqlDataSource1.SelectCommand = "select * from songs";
this.SqlDataSource1.UpdateCommand = "UPDATE [Songs] SET [AlbumId]=@albumId, [ArtistId]=@artistId, [SongTitle] = @SongTitle, [notes] = @notes WHERE [ID] = @ID";
this.SqlDataSource1.UpdateParameters.Clear();
this.SqlDataSource2.ConnectionString = connection;
this.SqlDataSource2.SelectCommand = "select * from albums";
}
private void BindGrid()
{
this.GridView1.DataBind();
}
private void BuildGrid()
{
this.GridView1.Columns.Clear();
AddColumn("id", "id", "Int32");
//AddColumn("Album", "albumId", "Int32");
AddDropDownColumn("Album", "albumId","id","name",SqlDataSource2);
AddColumn("Artist", "artistId", "Int32");
AddColumn("Title", "songTitle","String");
AddColumn("Notes", "notes", "String");
this.GridView1.DataKeyNames = new string[] { "id" };
}
private void AddColumn(string header, string name, string dataType)
{
BoundField bf = new BoundField();
bf.HeaderText = header;
bf.DataField = name;
bf.SortExpression = name;
bf.ReadOnly = false;
bf.HtmlEncode = true;
this.GridView1.Columns.Add(bf);
TypeCode tc = (TypeCode)Enum.Parse(typeof(TypeCode), dataType);
Parameter p = new Parameter(name, tc);
this.SqlDataSource1.UpdateParameters.Add(p);
}
private void AddDropDownColumn(string header, string name, string valueColumn, string displayColumn, SqlDataSource dataSource)
{
TemplateField tf = new TemplateField();
tf.HeaderText = header;
tf.ItemTemplate = new DDLTemplate(ListItemType.Item, name, null, null, null);
tf.EditItemTemplate = new DDLTemplate(ListItemType.EditItem, name, valueColumn, displayColumn, dataSource );
this.GridView1.Columns.Add(tf);
TypeCode tc = (TypeCode)Enum.Parse(typeof(TypeCode), "Int32");
Parameter p = new Parameter(name, tc);
this.SqlDataSource1.UpdateParameters.Add(p);
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = this.GridView1.Rows[e.RowIndex];
Control foundControl = RecursiveFindControl(row, "GridView1$ctl07$albumId_ddl");
if (foundControl != null)
{
DropDownList ddl = (DropDownList)foundControl;
string val = ddl.SelectedValue;
e.NewValues.Add("albumId", val);
}
BindGrid();
}
private Control RecursiveFindControl(Control root, string id)
{
if (root.ID != null)
{
if (root.ID.EndsWith(id))
{
return root;
}
}
if (root.ClientID != null)
{
if (root.ClientID.EndsWith(id))
{
return root;
}
}
foreach (Control subControl in root.Controls)
{
Control foundControl = RecursiveFindControl(subControl, id);
if (foundControl != null)
{
return foundControl;
}
}
return null;
}
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
BindGrid();
}
protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
}
}
protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
System.Console.WriteLine(e.Command);
}
}
public class DDLTemplate : System.Web.UI.Page, ITemplate
{
ListItemType templateType;
string column;
string valueColumn;
string displayColumn;
SqlDataSource dataSource;
public DDLTemplate(ListItemType type, string column, string valueColumn, string displayColumn, SqlDataSource dataSource)
{
this.templateType = type;
this.column = column;
this.valueColumn = valueColumn;
this.displayColumn = displayColumn;
this.dataSource = dataSource;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case ListItemType.Header:
break;
case ListItemType.Item:
Literal lc = new Literal();
lc.DataBinding += new EventHandler(lc_DataBinding);
container.Controls.Add(lc);
break;
case ListItemType.EditItem:
DropDownList ddl = new DropDownList();
ddl.ID = "albumId_ddl";
ddl.DataValueField = this.valueColumn;
ddl.DataTextField = this.displayColumn;
ddl.DataSource = this.dataSource;
ddl.DataBinding += new EventHandler(ddl_DataBinding);
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
container.Controls.Add(ddl);
break;
case ListItemType.Footer:
break;
}
}
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
Session["albumId_val"] = ddl.SelectedValue;
}
void lc_DataBinding(object sender, EventArgs e)
{
Literal lc = (Literal)sender;
GridViewRow row = (GridViewRow)lc.NamingContainer;
string text = DataBinder.Eval(row.DataItem, this.column).ToString();
lc.Text = text;
}
void ddl_DataBinding(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
string id = DataBinder.Eval(row.DataItem, column).ToString();
ddl.SelectedValue = id;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
}
}
}
|
Advertisement
| Hall of Fame |