Really struggline with how to populate a dropdownlist in a datagrid when i click the edit link:
Sub dgrdResults_PageIndexChanged (s as Object, e as DataGridPageChangedEventArgs)
dgrdResults.CurrentPageIndex = e.NewPageIndex
BindDataGrid
End Sub
Sub dgrdResults_CancelCommand(s as Object, e as DataGridCommandEventArgs)
dgrdResults.EditItemIndex = -1
BindDataGrid
End Sub
Sub dgrdResults_UpdateCommand(s as Object, e as DataGridCommandEventArgs)
Dim TempList as DropDownList
Dim TempValue as String
TempList = e.Item.FindControl("drpUnitRating")
TempValue = TempList.SelectedItem.Value
dgrdResults.EditItemIndex = -1
BindDataGrid
End Sub
Function BindRating()
'Dim colArrayList as New ArrayList
'colArrayList.Add("5")
'colArrayList.Add("4")
'colArrayList.Add("3")
'colArrayList.Add("2")
'colArrayList.Add("1")
'drpUnitRating.DataSource = colArrayList
'drpUnitRating.DataBind()
End Function
Sub dgrdResults_EditCommand(s as Object, e as DataGridCommandEventArgs)
dgrdResults.EditItemIndex = e.Item.ItemIndex
BindDataGrid
End Sub
.....
<asp:DataGrid
ID="dgrdResults"
AllowPaging="true"
AutoGenerateColumns="false"
PagerStyle-Mode="NumericPages" PagerStyle-PageButtonCount="5" PagerStyle-Position="Bottom"
PageSize="25"
OnPageIndexChanged="dgrdResults_PageIndexChanged"
OnEditCommand="dgrdResults_EditCommand"
OnUpdateCommand="dgrdResults_UpdateCommand"
OnCancelCommand="dgrdResults_CancelCommand"
CellPadding="0"
BorderWidth="0"
GridLines="None" CssClass="../fmcss.css"
runat="server" >
<columns>
<asp:TemplateColumn>
<itemTemplate>
<%# Container.DataItem("PRD_BRAND") %> <%# Container.DataItem("PRD_MODEL") %> <%# Container.DataItem("PRD_NAME") %> <%# Container.DataItem("PRD_CATEGORY_CD") %>
</itemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<itemTemplate>
<%# Container.DataItem("UNIT_RATING") %>
</itemTemplate>
<edititemtemplate>
<asp:DropDownList ID="drpUnitRating" DataTextField='<%# Container.DataItem("UNIT_RATING") %>' DataValueField='<%# Container.DataItem("UNIT_RATING") %>' DataSource='<%# BindRating %>' runat="server"></asp:DropDownList>
</edititemtemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="E" UpdateText="U" CancelText="C" />
</columns>
</asp:DataGrid>
I can do it either by connecting to a database or by just typing in say 5 values 1-5. I will be doing it both ways once I figure out how to do this. Right now I am just trying to just do it without the connecting to a database.
Thanks in advance to any replies.try this link:
http://aspnet.4guysfromrolla.com/articles/051904-1.aspx
hth,
Kev
Kevin,
Nice link.
Anyone know how to translate this to vb.net?
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// see if we are working with the row being edited
if (e.Item.ItemType == ListItemType.EditItem)
{
// populate the division DDL
DropDownList ddlDivision = (DropDownList) e.Item.FindControl("ddlDivision");
// connect to Access DB
OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["connString"]);
myConnection.Open();
const string SQL = @."SELECT DivisionID, Name FROM Divisions ORDER BY Name";
OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);
ddlDivision.DataSource = myCommand.ExecuteReader();
ddlDivision.DataBind();
myConnection.Close();
// now, select the appropriate division
int currentDivisionID = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "DivisionID"));
ListItem li = ddlDivision.Items.FindByValue(currentDivisionID.ToString());
if (li != null) li.Selected = true;
// finally, populate the department DDL based on the selected division
int currentDepartmentID = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "DepartmentID"));
if (li != null) li.Selected = true;
DropDownList ddlDepartment = (DropDownList) e.Item.FindControl("ddlDepartment");
PopulateDepartmentBasedOnDivision(ddlDepartment, ddlDivision, currentDepartmentID);
}
}
Saturday, March 24, 2012
populate dropdownlist in datagrid
Labels:
asp,
click,
datagrid,
dgrdresults_pageindexchanged,
dropdownlist,
linksub,
net,
object,
populate,
struggline
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment