Y
ycquak
Hi,
I have a page with a datagrid control. What I would like to do is when
I click on the update statement, I will update to the datagrid. However
the problem I am facing currently is when I click on update, the value
which I got from the controls generated by the datagrid edit template
is empty. Is there something I am missing out on? I have attached the
source codes below, please advice. Thanks!
Web User Control :
<aspataGrid id="participateGrid" runat="server"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
Width="100%" BorderColor="White" BorderStyle="None"
OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
ShowHeader="True">
<HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
<ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Outlet">
<EditItemTemplate>
<aspropDownList ID="ddlOutlet" Runat="server">
<asp:ListItem>...</asp:ListItem>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remarks">
<EditItemTemplate>
<asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
Columns="15" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>">
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
Text="<img src='delete.gif'"></asp:ButtonColumn>
</Columns>
</aspataGrid>
<asp:ImageButton ImageUrl="image.gif" id="btn_new"
runat="server"></asp:ImageButton>
This is the codebehind file update method :
protected void Update (object sender, DataGridCommandEventArgs e)
{
DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
("ddlOutlet");
TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
("txtRemarks"));
DataRow dr = dt.Rows[e.Item.DataSetIndex];
dr["Outlet"] = outlet.SelectedItem.Text;
dr["Remarks"] = remarks.Text;
saveData();
participateGrid.EditItemIndex = -1;
BindGrid();
}
private void saveData ()
{
//stores the information in a viewstate
ViewState ["Participate"] = dt;
}
//bind the data
private void BindGrid()
{
participateGrid.DataSource = dv;
participateGrid.DataBind();
}
I have a page with a datagrid control. What I would like to do is when
I click on the update statement, I will update to the datagrid. However
the problem I am facing currently is when I click on update, the value
which I got from the controls generated by the datagrid edit template
is empty. Is there something I am missing out on? I have attached the
source codes below, please advice. Thanks!
Web User Control :
<aspataGrid id="participateGrid" runat="server"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
Width="100%" BorderColor="White" BorderStyle="None"
OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
ShowHeader="True">
<HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
<ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Outlet">
<EditItemTemplate>
<aspropDownList ID="ddlOutlet" Runat="server">
<asp:ListItem>...</asp:ListItem>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remarks">
<EditItemTemplate>
<asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
Columns="15" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>">
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
Text="<img src='delete.gif'"></asp:ButtonColumn>
</Columns>
</aspataGrid>
<asp:ImageButton ImageUrl="image.gif" id="btn_new"
runat="server"></asp:ImageButton>
This is the codebehind file update method :
protected void Update (object sender, DataGridCommandEventArgs e)
{
DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
("ddlOutlet");
TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
("txtRemarks"));
DataRow dr = dt.Rows[e.Item.DataSetIndex];
dr["Outlet"] = outlet.SelectedItem.Text;
dr["Remarks"] = remarks.Text;
saveData();
participateGrid.EditItemIndex = -1;
BindGrid();
}
private void saveData ()
{
//stores the information in a viewstate
ViewState ["Participate"] = dt;
}
//bind the data
private void BindGrid()
{
participateGrid.DataSource = dv;
participateGrid.DataBind();
}