(जैसे छिपा मूल्य के आधार पर rowcolor स्थापित करने के लिए)onrowdatabound का उपयोग करने में gridview asp.net ग # छिपे हुए कोशिकाओं से मूल्यों को प्राप्त
आप एक gridview जो तब यह इस
<asp:GridView ID="Timeevents" runat="server"
OnRowDataBound="Timeevents_RowDataBound"
OnRowCommand = "Timeevents_RowCommand"
AutoGenerateColumns="False">
<columns>
<asp:BoundField DataField="CaseID" HeaderText="CaseID" Visible = "False" />
<asp:BoundField DataField="caseworkerID" HeaderText="CwID" Visible = "False" />
<asp:BoundField DataField="EventTypeID" HeaderText="EvTypeID" Visible = "False" />
<asp:BoundField DataField="CaseWorker" HeaderText="Case Worker" />
<asp:BoundField DataField="EventDate" HeaderText="Event Date" />
<asp:BoundField DataField="Code" HeaderText="Code" />
<asp:BoundField DataField="TotalUnits" HeaderText="Total Units" />
<asp:BoundField DataField="EventType" HeaderText="Event Type" />
<asp:BoundField DataField="UnitCost" HeaderText="Unit Cost" />
<asp:BoundField DataField="TotalCost" HeaderText="Total Cost"/>
<asp:TemplateField HeaderText="ADD">
<ItemTemplate>
<asp:Button ID="AddUnit" runat="server" Text=" +1 "
CommandName="AddUnit"
CommandArgument='<%# Eval("CaseID")+ ";" + Eval("CaseworkerID")+ ";" + Eval("EventDate")+ ";" + Eval("EventTypeID")+ ";" + ("1")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
तरह कोशिकाओं को छिपा दिया है, तो उन मानों को ऑन-डाउन डाटाबेस हैंडलर में उपयोग करना असंभव प्रतीत होता है (e.Row.Cells [2] .ext)
मुझे किसी भी बाउंडफ़िल्ड्स को दृश्यमान = "गलत" पर सेट न करने से इस समस्या को हल किया गया है, इसलिए वे दिखाई दे रहे हैं डिफ़ॉल्ट रूप से = "सत्य"। कोड को पीछे के कोड में ऑन-डाउन डाटाबेस हैंडलर में आवश्यक मान प्राप्त करना और फिर उन्हें बाद में अदृश्य बनाना। इस तरह।
protected void Timeevents_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ // just for the datarows
int a = (int.Parse(e.Row.Cells[2].Text));
if (a % 2 == 0)
{
e.Row.BackColor = System.Drawing.Color.Gainsboro;
}
else
{
e.Row.BackColor = System.Drawing.Color.White;
}
}
// end if so this applies to header and data rows
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false;
}
एक काफी हरी जा रहा है यह मेरे दौर में कई मंचों और डिबगिंग googling यह पता लगाने की है कि हैंडलर नहीं कर सकते छिपा डेटाबाउंड क्षेत्रों को देखने का एक अच्छा सौदा ले लिया और मैं सके कैसे के आधार पर rowcolour स्थापित करने के लिए की जवाब खोजने के लिए प्रतीत एक छिपी हुई फ़ील्ड इसलिए मैं आईडी को सिर्फ
यदि किसी विशेषज्ञ को बेहतर या वैकल्पिक तरीका पता है तो शायद वे कुछ कोड/टिप्पणियां चीयर्स भी जोड़ सकते हैं!
धन्यवाद वी बहुत Kaf कहते हैं ... लगता है और मुझे यह सोच कर मैं एक चतुर या कुछ और था वहाँ था !! – Sonny123