I have a datagrid that displays editable text fields (2 different price
fields) and a checkbox in every row.
It has a "SaveChange s" button at the bottom, which, when pressed, looks at
every checkbox in the datagrid, if it is checked, it updates the
corresponding rows prices.
That works, no problem.
What I need to do is that when a user clicks into either of the price text
fields, the checkbox automatically checks itself.
This will save having to click the checkbox after changing a field value.
I have a similar thing in ASP that I use, but the datagrid doesn't seem to
support client side code intuitively.
Here's the HTML side:
<asp:datagrid id="dgProductPr iceList" Runat="server" DataKeyField="i d"
AllowSorting="T rue" width="100%" AutoGenerateCol umns="False"
ItemStyle-CssClass="Item" AlternatingItem Style-CssClass="Alter nateItem"
HeaderStyle-CssClass="Heade r" CellSpacing="1" BorderWidth="0p x"
CellPadding="3" PageSize="30">
<AlternatingIte mStyle CssClass="Alter nateItem"></AlternatingItem Style>
<ItemStyle CssClass="Item" ></ItemStyle>
<HeaderStyle ForeColor="Whit e" CssClass="Heade r"></HeaderStyle>
<Columns>
<asp:TemplateCo lumn SortExpression= "SKU" HeaderText="SKU ">
<ItemStyle Wrap="False" HorizontalAlign ="Left"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("SKU") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "Name" HeaderText="Nam e">
<ItemStyle HorizontalAlign ="Left" VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("Name") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "price" HeaderText="Pri ce">
<HeaderStyle Wrap="False" HorizontalAlign ="Left"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign ="Right"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<asp:TextBox CssClass="FormI nput" Runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Price ") %>' Columns="5" ID="txtPrice">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "price2" HeaderText="Pri ce 2">
<HeaderStyle Wrap="False" HorizontalAlign ="Left"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign ="Right"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<asp:TextBox id="txtPrice2" CssClass="FormI nput"
Runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Price 2") %>'
Columns="5">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Sel ect">
<ItemTemplate >
<asp:CheckBox id="chkSelectio n" runat="server"
Checked="false" EnableViewState ="true"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle Position="TopAn dBottom" CssClass="FormL abel"
Mode="NumericPa ges"></PagerStyle>
</asp:datagrid>
<asp:imagebutto n id="btnSaveChan ges" runat="server"
ImageUrl="image s/btnSaveChanges. gif"></asp:imagebutton >
*************** *************** *************** *************** *************** *
**********
The code that binds a datatable to the datagrid:
Sub FillProductPric eList(ByVal sortexpression As String)
Session("AdminP roductPrefsCate gory") =
lstCategories.S electedItem.Val ue
Session("AdminP roductPrefsName ") = inName.Text
Session("AdminP roductPrefsSKU" ) = inSKU.Text
Dim ProdManager As New StoreObjects.Pr oductManager
Try
Dim dtProducts As DataTable =
ProdManager.Get Products2(lstCa tegories.Select edItem.Value, inName.Text,
inSKU.Text, sortexpression, -1)
Me.dgProductPri ceList.DataSour ce = dtProducts
Me.dgProductPri ceList.DataBind ()
lblResponse.Tex t = dtProducts.Rows .Count & " products found"
Catch Ex As Exception
lblError.Text = Ex.Message
End Try
ProdManager = Nothing
End Sub
fields) and a checkbox in every row.
It has a "SaveChange s" button at the bottom, which, when pressed, looks at
every checkbox in the datagrid, if it is checked, it updates the
corresponding rows prices.
That works, no problem.
What I need to do is that when a user clicks into either of the price text
fields, the checkbox automatically checks itself.
This will save having to click the checkbox after changing a field value.
I have a similar thing in ASP that I use, but the datagrid doesn't seem to
support client side code intuitively.
Here's the HTML side:
<asp:datagrid id="dgProductPr iceList" Runat="server" DataKeyField="i d"
AllowSorting="T rue" width="100%" AutoGenerateCol umns="False"
ItemStyle-CssClass="Item" AlternatingItem Style-CssClass="Alter nateItem"
HeaderStyle-CssClass="Heade r" CellSpacing="1" BorderWidth="0p x"
CellPadding="3" PageSize="30">
<AlternatingIte mStyle CssClass="Alter nateItem"></AlternatingItem Style>
<ItemStyle CssClass="Item" ></ItemStyle>
<HeaderStyle ForeColor="Whit e" CssClass="Heade r"></HeaderStyle>
<Columns>
<asp:TemplateCo lumn SortExpression= "SKU" HeaderText="SKU ">
<ItemStyle Wrap="False" HorizontalAlign ="Left"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("SKU") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "Name" HeaderText="Nam e">
<ItemStyle HorizontalAlign ="Left" VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("Name") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "price" HeaderText="Pri ce">
<HeaderStyle Wrap="False" HorizontalAlign ="Left"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign ="Right"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<asp:TextBox CssClass="FormI nput" Runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Price ") %>' Columns="5" ID="txtPrice">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn SortExpression= "price2" HeaderText="Pri ce 2">
<HeaderStyle Wrap="False" HorizontalAlign ="Left"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign ="Right"
VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<asp:TextBox id="txtPrice2" CssClass="FormI nput"
Runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Price 2") %>'
Columns="5">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Sel ect">
<ItemTemplate >
<asp:CheckBox id="chkSelectio n" runat="server"
Checked="false" EnableViewState ="true"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle Position="TopAn dBottom" CssClass="FormL abel"
Mode="NumericPa ges"></PagerStyle>
</asp:datagrid>
<asp:imagebutto n id="btnSaveChan ges" runat="server"
ImageUrl="image s/btnSaveChanges. gif"></asp:imagebutton >
*************** *************** *************** *************** *************** *
**********
The code that binds a datatable to the datagrid:
Sub FillProductPric eList(ByVal sortexpression As String)
Session("AdminP roductPrefsCate gory") =
lstCategories.S electedItem.Val ue
Session("AdminP roductPrefsName ") = inName.Text
Session("AdminP roductPrefsSKU" ) = inSKU.Text
Dim ProdManager As New StoreObjects.Pr oductManager
Try
Dim dtProducts As DataTable =
ProdManager.Get Products2(lstCa tegories.Select edItem.Value, inName.Text,
inSKU.Text, sortexpression, -1)
Me.dgProductPri ceList.DataSour ce = dtProducts
Me.dgProductPri ceList.DataBind ()
lblResponse.Tex t = dtProducts.Rows .Count & " products found"
Catch Ex As Exception
lblError.Text = Ex.Message
End Try
ProdManager = Nothing
End Sub
Comment